-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_MinHeap.cpp
More file actions
60 lines (51 loc) · 1.59 KB
/
Copy pathtest_MinHeap.cpp
File metadata and controls
60 lines (51 loc) · 1.59 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
#include "catch.hpp"
#include "MinHeap.hpp" // 包含你的 MinHeap 类定义
TEST_CASE("Test MinHeap functionality", "[MinHeap]") {
MinHeap<int> minHeap;
SECTION("Heap should be initially empty") {
REQUIRE(minHeap.IsEmpty() == true);
}
SECTION("Insert elements into MinHeap") {
REQUIRE(minHeap.Insert(5) == true);
REQUIRE(minHeap.Insert(3) == true);
REQUIRE(minHeap.Insert(7) == true);
REQUIRE(minHeap.IsEmpty() == false);
}
SECTION("RemoveMin on MinHeap") {
minHeap.Insert(5);
minHeap.Insert(3);
minHeap.Insert(7);
int min;
REQUIRE(minHeap.RemoveMin(min) == true);
REQUIRE(min == 3); // 3 是最小的元素
REQUIRE(minHeap.RemoveMin(min) == true);
REQUIRE(min == 5); // 接下来是 5
}
SECTION("MinHeap should be not full after initialization") {
REQUIRE(minHeap.IsFull() == false);
}
SECTION("MakeEmpty on MinHeap") {
minHeap.Insert(5);
minHeap.Insert(3);
minHeap.MakeEmpty();
REQUIRE(minHeap.IsEmpty() == true);
}
SECTION("1") {
MinHeap<int> heap; int mov;
heap.Insert(0);
heap.RemoveMin(mov);
std::cout << mov << std::endl;
heap.Insert(10);
heap.Insert(20);
heap.RemoveMin(mov);
std::cout << mov << std::endl;
heap.Insert(15);
heap.Insert(15);
heap.RemoveMin(mov);
std::cout << mov << std::endl;
heap.RemoveMin(mov);
std::cout << mov << std::endl;
heap.RemoveMin(mov);
std::cout << mov << std::endl;
}
}