-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryHeapTests.cpp
More file actions
80 lines (71 loc) · 2.51 KB
/
BinaryHeapTests.cpp
File metadata and controls
80 lines (71 loc) · 2.51 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
#include <memory>
#include <limits>
#include <functional>
#include "CppUnitTest.h"
#include "BinaryHeap.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;
namespace AlgorithmsTests
{
TEST_CLASS(BinaryHeapTests)
{
public:
TEST_METHOD(BinaryHeap_Int_WhenInsertSingleElement_ExpectSameElementReturned)
{
// Arrange
std::unique_ptr<BinaryHeap<int>> testHeap(new BinaryHeap<int>(10, INT32_MIN));
// Act
testHeap->Insert(1);
auto result1 = testHeap->Delete_Min();
// Assert
Assert::AreEqual<int>(1, result1);
}
TEST_METHOD(BinaryHeap_Int_WhenInsertThreeElements_ExpectSmallestElementReturnedFirst)
{
// Arrange
std::unique_ptr<BinaryHeap<int>> testHeap(new BinaryHeap<int>(10, INT32_MIN));
// Act
testHeap->Insert(100);
testHeap->Insert(200);
testHeap->Insert(300);
auto result = testHeap->Delete_Min();
// Assert
Assert::AreEqual<int>(100, result);
}
TEST_METHOD(BinaryHeap_Int_WhenInsertThreeElements_ExpectLargetsElementReturnedLast)
{
// Arrange
std::unique_ptr<BinaryHeap<int>> testHeap(new BinaryHeap<int>(10, INT32_MIN));
// Act
testHeap->Insert(100);
testHeap->Insert(200);
testHeap->Insert(300);
testHeap->Delete_Min();
testHeap->Delete_Min();
auto result = testHeap->Delete_Min();
// Assert
Assert::AreEqual<int>(300, result);
}
TEST_METHOD(BinaryHeap_Int_WhenDeleteFromEmptyHeap_ExpectException)
{
// Arrange
std::unique_ptr<BinaryHeap<int>> testHeap(new BinaryHeap<int>(10, INT32_MIN));
function<void (void)> testPtr = [&testHeap] { testHeap->Delete_Min(); }; // When calling function() with a pointer like: ptr->func() include in capture.
std::wstring message( L"Expected Exception to be thrown" );
// Act & Assert
Assert::ExpectException<std::exception>(testPtr, message.c_str());
}
TEST_METHOD(BinaryHeap_Int_WhenInsertIntoFullHeap_ExpectException)
{
// Arrange
std::unique_ptr<BinaryHeap<int>> testHeap(new BinaryHeap<int>(10, INT32_MIN));
// Fill heap to max
for (int x = 0; x < 10; x++)
testHeap->Insert(x);
function<void (void)> testPtr = [&testHeap] { testHeap->Insert(10); }; // When calling function() with a pointer like: ptr->func() include in capture.
std::wstring message( L"Expected Exception to be thrown" );
// Act & Assert
Assert::ExpectException<std::exception>(testPtr, message.c_str());
}
};
}