-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtest.cpp
More file actions
126 lines (113 loc) · 2.78 KB
/
htest.cpp
File metadata and controls
126 lines (113 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "heap.h"
#include "gtest/gtest.h"
#include <iostream>
#include <string>
using namespace std;
class HeapTest: public testing::Test{
protected:
HeapTest(): minHeap(2, lcomp), maxHeap(4, gcomp), maxStringHeap(3, gscomp){}
virtual ~HeapTest(){}
virtual void SetUp(){}
virtual void TearDown(){}
//comparators
less<int>lcomp;
greater<int>gcomp;
greater<string>gscomp;
//initialize heaps
Heap<int, less<int> > minHeap;
Heap<int, greater<int> > maxHeap;
Heap<string, greater<string> > maxStringHeap;
};
//testing empty, push, pop, and top for int min heap
TEST_F(HeapTest, minNominal){
EXPECT_EQ(minHeap.empty(), 1);
minHeap.push(5);
EXPECT_EQ(minHeap.empty(), 0);
minHeap.push(7);
minHeap.push(9);
minHeap.push(2);
minHeap.push(10);
minHeap.push(0);
minHeap.push(-1);
minHeap.push(-2);
minHeap.push(-3);
EXPECT_EQ(minHeap.top(), -3);
minHeap.pop();
minHeap.pop();
minHeap.push(-10);
EXPECT_EQ(minHeap.top(), -10);
minHeap.pop();
minHeap.pop();
minHeap.pop();
EXPECT_EQ(minHeap.top(), 2);
minHeap.pop();
minHeap.pop();
EXPECT_EQ(minHeap.top(), 7);
minHeap.pop();
minHeap.pop();
minHeap.pop();
EXPECT_EQ(minHeap.empty(), 1);
}
//testing empty, push, pop, and top for int max heap
TEST_F(HeapTest, maxNominal){
EXPECT_EQ(maxHeap.empty(), 1);
maxHeap.push(5);
EXPECT_EQ(maxHeap.empty(), 0);
maxHeap.push(-5);
maxHeap.push(20);
maxHeap.push(10);
maxHeap.push(50);
maxHeap.push(40);
maxHeap.push(30);
maxHeap.push(25);
maxHeap.push(21);
EXPECT_EQ(maxHeap.top(), 50);
maxHeap.pop();
maxHeap.pop();
maxHeap.push(60);
EXPECT_EQ(maxHeap.top(), 60);
maxHeap.pop();
maxHeap.pop();
maxHeap.pop();
maxHeap.pop();
EXPECT_EQ(maxHeap.top(), 20);
maxHeap.pop();
maxHeap.pop();
EXPECT_EQ(maxHeap.top(), 5);
maxHeap.pop();
EXPECT_EQ(maxHeap.top(), -5);
maxHeap.pop();
EXPECT_EQ(maxHeap.empty(), 1);
}
//testing empty, push, pop, and top for string max heap
TEST_F(HeapTest, stringNominal){
EXPECT_EQ(maxStringHeap.empty(), 1);
maxStringHeap.push("acorn");
EXPECT_EQ(maxStringHeap.empty(), 0);
maxStringHeap.push("zeta");
maxStringHeap.push("aaron");
maxStringHeap.push("zebra");
maxStringHeap.push("aaardvark");
maxStringHeap.push("zz");
maxStringHeap.push("zzz");
maxStringHeap.push("zzzz");
maxStringHeap.push("zzzzz");
EXPECT_EQ(maxStringHeap.top(), "zzzzz");
maxStringHeap.pop();
maxStringHeap.pop();
maxStringHeap.push("zzzzzz");
EXPECT_EQ(maxStringHeap.top(), "zzzzzz");
maxStringHeap.pop();
maxStringHeap.pop();
maxStringHeap.pop();
EXPECT_EQ(maxStringHeap.top(), "zeta");
maxStringHeap.pop();
EXPECT_EQ(maxStringHeap.top(), "zebra");
maxStringHeap.pop();
EXPECT_EQ(maxStringHeap.top(), "acorn");
maxStringHeap.pop();
EXPECT_EQ(maxStringHeap.top(), "aaron");
maxStringHeap.pop();
EXPECT_EQ(maxStringHeap.top(), "aaardvark");
maxStringHeap.pop();
}