tesseract 5.2.0
Loading...
Searching...
No Matches
tesseract::HeapTest Class Reference
Inheritance diagram for tesseract::HeapTest:

Public Member Functions

 ~HeapTest () override
 
void PushTestData (GenericHeap< IntKDPair > *heap, KDVector *v)
 
void VerifyHeapVectorMatch (GenericHeap< IntKDPair > *heap, KDVector *v)
 

Protected Member Functions

void SetUp () override
 

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 ( )
inlineoverrideprotected

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 }

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