forked from huffz/Huffman_Coding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCUtests.c
146 lines (118 loc) · 3.55 KB
/
CUtests.c
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "testsfunctions.c"
#include "CUnit/Basic.h"
void test_create_node() // testando create_node
{
node *new = (node *) malloc(sizeof(node));
new->f = 10;
new->c = 'x';
new->next = NULL;
new->left = NULL;
new->right = NULL;
node *test = create_node('x', 10, NULL, NULL);
CU_ASSERT(test != NULL);
CU_ASSERT_EQUAL(new->f, test->f);
CU_ASSERT_EQUAL(new->c, test->c);
CU_ASSERT_PTR_EQUAL(new->next, test->next);
CU_ASSERT_PTR_EQUAL(new->left, test->left);
CU_ASSERT_PTR_EQUAL(new->right, test->right);
}
void test_add() // testando add
{
node *new1 = create_node('x', 10, NULL, NULL);
node *new2 = create_node('y', 6, NULL, NULL);
node *test = add(NULL, 'x', 10, NULL, NULL); // lista vazia retorna um new..
CU_ASSERT(test != NULL);
CU_ASSERT_EQUAL(new1->f, test->f);
CU_ASSERT_EQUAL(new1->c, test->c);
CU_ASSERT_PTR_EQUAL(new1->next, test->next);
CU_ASSERT_PTR_EQUAL(new1->left, test->left);
CU_ASSERT_PTR_EQUAL(new1->right, test->right);
test = add(test, 'y', 6, NULL, NULL); // lista com 1 elemento retorna head..
CU_ASSERT(test != NULL);
CU_ASSERT_EQUAL(new2->f, test->f);
CU_ASSERT_EQUAL(new2->c, test->c);
CU_ASSERT_PTR_EQUAL(new2->left, test->left);
CU_ASSERT_PTR_EQUAL(new2->right, test->right);
}
void test_make_tree() // testando make_tree
{
node *aux1, *aux2, *head, *tail;
tail = create_node('y', 20, NULL, NULL); // criando 2 nos e fazendo uma lista com eles..
head = create_node('x', 10, NULL, NULL);
head->next = tail; // lista feita..
aux1 = head;
aux2 = tail;
head = make_tree(head);
CU_ASSERT(head != NULL);
CU_ASSERT_EQUAL(head->c, '*');
CU_ASSERT_EQUAL(head->f, 30);
CU_ASSERT_EQUAL(head->left, aux1);
CU_ASSERT_EQUAL(head->right, aux2);
}
void test_create_hash()
{
hash_tree *new = create_hash();
CU_ASSERT(new != NULL);
}
void test_create_stack() // estar como criars.. nome feio!
{
stack *new = criars();
CU_ASSERT(new != NULL);
}
void test_create_t_node()
{
h_tree *new = (h_tree *) malloc(sizeof(h_tree));
new->c = 'x';
new->left = NULL;
new->right = NULL;
h_tree *test = create_t_node('x', NULL, NULL);
CU_ASSERT(test != NULL);
CU_ASSERT_EQUAL(new->c, test->c);
CU_ASSERT_PTR_EQUAL(new->left, test->left);
CU_ASSERT_PTR_EQUAL(new->right, test->right);
}
int main()
{
// Initialize the CUnit test registry
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
// Sets the basic run mode, CU_BRM_VERBOSE will show maximum output of run details
// Other choices are: CU_BRM_SILENT and CU_BRM_NORMAL
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_pSuite pSuite = NULL, pSuite2 = NULL;
// Add a suite to the registry
pSuite = CU_add_suite("TEST", 0, 0);
// Always check if add was successful
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}
// Add the test to the suite
if (NULL == CU_add_test(pSuite, "test - 1", test_create_node)) {
CU_cleanup_registry();
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test - 2", test_add)) {
CU_cleanup_registry();
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test - 3", test_make_tree)) {
CU_cleanup_registry();
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test - 4", test_create_hash)) {
CU_cleanup_registry();
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test - 5", test_create_stack)) {
CU_cleanup_registry();
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test - 6", test_create_t_node)) {
CU_cleanup_registry();
return CU_get_error();
}
// Run the tests and show the run summary
CU_basic_run_tests();
return CU_get_error();
}