tesseract v5.3.3.20231005
tesseract::HeapTest Class Reference
Inheritance diagram for tesseract::HeapTest:
testing::Test

Public Member Functions

 ~HeapTest () override
 
void PushTestData (GenericHeap< IntKDPair > *heap, KDVector *v)
 
void VerifyHeapVectorMatch (GenericHeap< IntKDPair > *heap, KDVector *v)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 

Protected Member Functions

void SetUp () override
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
virtual void SetUp ()
 
virtual void TearDown ()
 

Additional Inherited Members

- Static Public Member Functions inherited from testing::Test
static void SetUpTestSuite ()
 
static void TearDownTestSuite ()
 
static void TearDownTestCase ()
 
static void SetUpTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool IsSkipped ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 

Detailed Description

Definition at line 26 of file heap_test.cc.

Constructor & Destructor Documentation

◆ ~HeapTest()

tesseract::HeapTest::~HeapTest ( )
overridedefault

Member Function Documentation

◆ PushTestData()

void tesseract::HeapTest::PushTestData ( GenericHeap< IntKDPair > *  heap,
KDVector v 
)
inline

Definition at line 35 of file heap_test.cc.

35 {
36 for (size_t i = 0; i < countof(test_data); ++i) {
37 IntKDPair pair(test_data[i], i);
38 heap->Push(&pair);
39 v->push_back(pair);
40 }
41 }
KDPairInc< int, int > IntKDPair
Definition: kdpair.h:191
constexpr size_t countof(T const (&)[N]) noexcept
Definition: serialis.h:34
int test_data[]
Definition: heap_test.cc:23

◆ SetUp()

void tesseract::HeapTest::SetUp ( )
inlineoverrideprotectedvirtual

Reimplemented from testing::Test.

Definition at line 28 of file heap_test.cc.

28 {
29 std::locale::global(std::locale(""));
30 }

◆ VerifyHeapVectorMatch()

void tesseract::HeapTest::VerifyHeapVectorMatch ( GenericHeap< IntKDPair > *  heap,
KDVector v 
)
inline

Definition at line 44 of file heap_test.cc.

44 {
45 EXPECT_FALSE(heap->empty());
46 EXPECT_EQ(heap->size(), v->size());
47 // Sort the vector and check that the keys come out of the heap in the same
48 // order as v.
49 // Also check that the indices match, except for 9, which is duplicated.
50 std::sort(v->begin(), v->end());
51 // Check that we have increasing order.
52 EXPECT_LT((*v)[0].key(), v->back().key());
53 for (unsigned i = 0; i < v->size(); ++i) {
54 EXPECT_EQ((*v)[i].key(), heap->PeekTop().key());
55 // Indices don't necessarily match for equal keys, so don't test them.
56 if (i + 1 < v->size() && (*v)[i + 1].key() == (*v)[i].key()) {
57 while (i + 1 < v->size() && (*v)[i + 1].key() == (*v)[i].key()) {
58 heap->Pop(nullptr);
59 ++i;
60 EXPECT_FALSE(heap->empty());
61 EXPECT_EQ((*v)[i].key(), heap->PeekTop().key());
62 }
63 } else {
64 // The indices must also match if the key is unique.
65 EXPECT_EQ((*v)[i].data(), heap->PeekTop().data());
66 }
67 EXPECT_FALSE(heap->empty());
68 EXPECT_TRUE(heap->Pop(nullptr));
69 }
70 EXPECT_TRUE(heap->empty());
71 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
#define EXPECT_TRUE(condition)
Definition: gtest.h:1982
#define EXPECT_FALSE(condition)
Definition: gtest.h:1986
#define EXPECT_LT(val1, val2)
Definition: gtest.h:2049

The documentation for this class was generated from the following file: