-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBinaryHeapTest.cpp
More file actions
52 lines (40 loc) · 1.01 KB
/
Copy pathBinaryHeapTest.cpp
File metadata and controls
52 lines (40 loc) · 1.01 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
//
// Created by haibo on 4/9/18.
//
#include "gtest/gtest.h"
#include "../../algorithm/datastructure/BinaryHeap.h"
TEST(BinaryHeapTest, SimpleTest) {
BinaryHeap<int> bh;
bh.add(2);
bh.add(1);
bh.add(3);
ASSERT_TRUE(bh.exists(1));
ASSERT_FALSE(bh.exists(4));
ASSERT_EQ(bh.top(), 1);
ASSERT_EQ(bh.size(), 3);
bh.add(0);
ASSERT_TRUE(bh.exists(1));
ASSERT_FALSE(bh.exists(4));
ASSERT_EQ(bh.top(), 0);
ASSERT_EQ(bh.size(), 4);
bh.add(4);
ASSERT_TRUE(bh.exists(1));
ASSERT_TRUE(bh.exists(4));
ASSERT_EQ(bh.top(), 0);
ASSERT_EQ(bh.size(), 5);
bh.remove(1);
ASSERT_FALSE(bh.exists(1));
ASSERT_TRUE(bh.exists(4));
ASSERT_EQ(bh.top(), 0);
ASSERT_EQ(bh.size(), 4);
bh.remove(0);
ASSERT_FALSE(bh.exists(1));
ASSERT_TRUE(bh.exists(4));
ASSERT_EQ(bh.top(), 2);
ASSERT_EQ(bh.size(), 3);
bh.add(1);
ASSERT_TRUE(bh.exists(1));
ASSERT_TRUE(bh.exists(4));
ASSERT_EQ(bh.top(), 1);
ASSERT_EQ(bh.size(), 4);
}