ReactOS  0.4.15-dev-499-g1f31905
heap_test.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <algorithm>
3 #include <functional>
4 
6 
7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8 using namespace std;
9 #endif
10 
11 //
12 // TestCase class
13 //
14 class HeapTest : public CPPUNIT_NS::TestCase
15 {
17  CPPUNIT_TEST(mkheap0);
18  CPPUNIT_TEST(mkheap1);
19  CPPUNIT_TEST(pheap1);
20  CPPUNIT_TEST(pheap2);
22 
23 protected:
24  void mkheap0();
25  void mkheap1();
26  void pheap1();
27  void pheap2();
28 };
29 
31 
32 //
33 // tests implementation
34 //
36 {
37  int numbers[6] = { 5, 10, 4, 13, 11, 19 };
38 
39  make_heap(numbers, numbers + 6);
40  CPPUNIT_ASSERT(numbers[0]==19)
41  pop_heap(numbers, numbers + 6);
42  CPPUNIT_ASSERT(numbers[0]==13)
43  pop_heap(numbers, numbers + 5);
44  CPPUNIT_ASSERT(numbers[0]==11)
45  pop_heap(numbers, numbers + 4);
46  CPPUNIT_ASSERT(numbers[0]==10)
47  pop_heap(numbers, numbers + 3);
48  CPPUNIT_ASSERT(numbers[0]==5)
49  pop_heap(numbers, numbers + 2);
50  CPPUNIT_ASSERT(numbers[0]==4)
51  pop_heap(numbers, numbers + 1);
52 }
54 {
55  int numbers[6] = { 5, 10, 4, 13, 11, 19 };
56 
57  make_heap(numbers, numbers + 6, greater<int>());
58 
59  CPPUNIT_ASSERT(numbers[0]==4)
60  pop_heap(numbers, numbers + 6, greater<int>());
61  CPPUNIT_ASSERT(numbers[0]==5)
62  pop_heap(numbers, numbers + 5, greater<int>());
63  CPPUNIT_ASSERT(numbers[0]==10)
64  pop_heap(numbers, numbers + 4, greater<int>());
65  CPPUNIT_ASSERT(numbers[0]==11)
66  pop_heap(numbers, numbers + 3, greater<int>());
67  CPPUNIT_ASSERT(numbers[0]==13)
68  pop_heap(numbers, numbers + 2, greater<int>());
69  CPPUNIT_ASSERT(numbers[0]==19)
70 }
72 {
73  vector<int> v;
74 
75  v.push_back(1);
76  v.push_back(20);
77  v.push_back(4);
78  make_heap(v.begin(), v.end());
79 
80  v.push_back(7);
81  push_heap(v.begin(), v.end());
82 
83  sort_heap(v.begin(), v.end());
84 
85  CPPUNIT_ASSERT(v[0]==1);
86  CPPUNIT_ASSERT(v[1]==4);
87  CPPUNIT_ASSERT(v[2]==7);
88  CPPUNIT_ASSERT(v[3]==20);
89 }
91 {
92  vector<int> v;
93 
94  v.push_back(1);
95  v.push_back(20);
96  v.push_back(4);
97  make_heap(v.begin(), v.end(), greater<int>());
98 
99  v.push_back(7);
100  push_heap(v.begin(), v.end(), greater<int>());
101 
102  sort_heap(v.begin(), v.end(), greater<int>());
103 
104  CPPUNIT_ASSERT(v[0]==20);
105  CPPUNIT_ASSERT(v[1]==7);
106  CPPUNIT_ASSERT(v[2]==4);
107  CPPUNIT_ASSERT(v[3]==1);
108 }
void mkheap0()
Definition: heap_test.cpp:35
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
void pheap1()
Definition: heap_test.cpp:71
void mkheap1()
Definition: heap_test.cpp:53
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
_STLP_INLINE_LOOP void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
Definition: _heap.h:99
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
Definition: _heap.c:138
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
Definition: _heap.c:65
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
CPPUNIT_TEST_SUITE_REGISTRATION(HeapTest)
const GLdouble * v
Definition: gl.h:2040
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
Definition: _heap.c:206
void pheap2()
Definition: heap_test.cpp:90