forked from Turupawn/GenerateHuffman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
57 lines (48 loc) · 1.61 KB
/
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
#include "Test.h"
bool checkCodesAreDifferent(map<char,string> codes)
{
for(map<char,string>::iterator i = codes.begin(); i != codes.end(); i++)
{
map<char,string>::iterator j = i;
j++;
for(; j != codes.end(); j++)
{
if((*i).second == (*j).second)
{
return false;
}
}
}
return true;
}
void test()
{
static const char arr[] = {'a', 'b', 'c', 'd', 'e', 'f'};
vector<char> vector1_test1 (arr, arr + sizeof(arr) / sizeof(arr[0]) );
static const int arr2[] = {10, 5, 3, 7, 9, 20};
vector<int> vector2_test1 (arr2, arr2 + sizeof(arr2) / sizeof(arr2[0]) );
map<char,string> answer1 = getHuffman(vector1_test1, vector2_test1);
static const char arrx[] = {'x', 'y', 'z'};
vector<char> vector1_test2 (arrx, arrx + sizeof(arrx) / sizeof(arrx[0]) );
static const int arr2x[] = {10, 5, 15,};
vector<int> vector2_test2 (arr2x, arr2x + sizeof(arr2x) / sizeof(arr2x[0]) );
map<char,string> answer2 = getHuffman(vector1_test2, vector2_test2);
if(answer1['a'].length() == 3// == "111"
&& answer1['b'].length() == 4// == "1011"
&& answer1['c'].length() == 4// == "1010"
&& answer1['d'].length() == 3// == "100"
&& answer1['e'].length() == 3// == "110"
&& answer1['f'].length() == 1// == "0"
&& checkCodesAreDifferent(answer1)
&& answer2['x'].length() == 2// == "11"
&& answer2['y'].length() == 2// == "10"
&& answer2['z'].length() == 1// == "0"
&& checkCodesAreDifferent(answer2)
)
{
cout<<"Test: Pass"<<endl;
}else
{
cout<<"Test: Fail"<<endl;
}
}