-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman_node_test.cpp
121 lines (98 loc) · 4.57 KB
/
huffman_node_test.cpp
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
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "huffman_node.h"
#include <memory>
using namespace std;
TEST_CASE( "Huffman node default constructor test", "[huffman_node()]" ) {
huffman_node h = huffman_node();
REQUIRE(h.getLetter() == 0);
REQUIRE(h.getFrequency() == 0);
REQUIRE(h.getLeft() == nullptr);
REQUIRE(h.getRight() == nullptr);
}
TEST_CASE( "Huffman node custom constructor test", "[huffman_node(char, int, const shared_ptr<huffman_node>, const shared_ptr<huffman_node>)]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h = huffman_node('c', 3, left, right);
REQUIRE(h.getLetter() == 'c');
REQUIRE(h.getFrequency() == 3);
REQUIRE(h.getLeft() == left);
REQUIRE(h.getRight() == right);
}
TEST_CASE( "Huffman node copy constructor test", "[huffman_node(const huffman_node& old_huffman_node)]" ) {
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h_1 = huffman_node('c', 3, left, right);
huffman_node h_2(h_1);
REQUIRE(h_1.getLetter() == h_2.getLetter());
REQUIRE(h_1.getFrequency() == h_2.getFrequency());
REQUIRE(h_1.getLeft() == h_2.getLeft());
REQUIRE(h_1.getRight() == h_2.getRight());
}
TEST_CASE("Huffman node move constructor test", "[huffman_node(const huffman_node&& old_huffman_node)]") {
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h_1 = huffman_node('c', 3, left, right);
huffman_node h_2 = move(h_1);
REQUIRE(h_2.getLetter() == 'c');
REQUIRE(h_2.getFrequency() == 3);
REQUIRE(h_2.getLeft() == left);
REQUIRE(h_2.getRight() == right);
REQUIRE(h_1.getLetter() == 0);
REQUIRE(h_1.getFrequency() == 0);
REQUIRE(h_1.getLeft() == nullptr);
REQUIRE(h_1.getRight() == nullptr);
}
TEST_CASE("Huffman node assignment operator test", "[operator=(const huffman_node& other_huffman_node)]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h_1 = huffman_node('c', 3, left, right);
huffman_node h_2 = h_1;
REQUIRE(h_1.getLetter() == h_2.getLetter());
REQUIRE(h_1.getFrequency() == h_2.getFrequency());
REQUIRE(h_1.getLeft() == h_2.getLeft());
REQUIRE(h_1.getRight() == h_2.getRight());
}
TEST_CASE("Huffman node move assignment operator test", "[operator=(const huffman_node&& other_huffman_node)]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h_1 = huffman_node('c', 3, left, right);
huffman_node h_2 = move(h_1);
REQUIRE(h_2.getLetter() == 'c');
REQUIRE(h_2.getFrequency() == 3);
REQUIRE(h_2.getLeft() == left);
REQUIRE(h_2.getRight() == right);
REQUIRE(h_1.getLetter() == 0);
REQUIRE(h_1.getFrequency() == 0);
REQUIRE(h_1.getLeft() == nullptr);
REQUIRE(h_1.getRight() == nullptr);
}
TEST_CASE("Huffman node getLetter test", "[getLetter()]"){
huffman_node h = huffman_node('a', 1, nullptr, nullptr);
REQUIRE(h.getLetter() == 'a');
}
TEST_CASE("Huffman node getFrequency test", "[getFrequency()]"){
huffman_node h = huffman_node('a', 1, nullptr, nullptr);
REQUIRE(h.getFrequency() == 1);
}
TEST_CASE("Huffman node getLeft test", "[getLeft()]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h = huffman_node('c', 3, left, right);
REQUIRE(h.getLeft() == left);
}
TEST_CASE("Huffman node getRight test", "[getRight()]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h = huffman_node('c', 3, left, right);
REQUIRE(h.getRight() == right);
}
TEST_CASE( "Huffman node custom constructor test 2", "[huffman_node(const shared_ptr<huffman_node>, const shared_ptr<huffman_node>)]"){
shared_ptr<huffman_node> left(new huffman_node('a', 1, nullptr, nullptr));
shared_ptr<huffman_node> right(new huffman_node('b', 2, nullptr, nullptr));
huffman_node h = huffman_node(left, right);
REQUIRE(h.getLetter() == '\0');
REQUIRE(h.getFrequency() == left->getFrequency() + right->getFrequency());
REQUIRE(h.getLeft() == left);
REQUIRE(h.getRight() == right);
}