tesseract  5.0.0-alpha-619-ge9db
tesseract::HeapTest Class Reference
Inheritance diagram for tesseract::HeapTest:

Public Member Functions

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

Protected Member Functions

void SetUp ()
 

Detailed Description

Definition at line 27 of file heap_test.cc.

Constructor & Destructor Documentation

◆ ~HeapTest()

tesseract::HeapTest::~HeapTest ( )
virtualdefault

Member Function Documentation

◆ PushTestData()

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

Definition at line 36 of file heap_test.cc.

36  {
37  for (size_t i = 0; i < ARRAYSIZE(test_data); ++i) {
38  IntKDPair pair(test_data[i], i);
39  heap->Push(&pair);
40  v->push_back(pair);
41  }
42  }

◆ SetUp()

void tesseract::HeapTest::SetUp ( )
inlineprotected

Definition at line 29 of file heap_test.cc.

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

◆ VerifyHeapVectorMatch()

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

Definition at line 45 of file heap_test.cc.

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

The documentation for this class was generated from the following file:
tesseract::test_data
int test_data[]
Definition: heap_test.cc:24
ARRAYSIZE
#define ARRAYSIZE(arr)
Definition: include_gunit.h:53
tesseract::IntKDPair
KDPairInc< int, int > IntKDPair
Definition: kdpair.h:179