-
Notifications
You must be signed in to change notification settings - Fork 9
/
unit.c
75 lines (55 loc) · 1004 Bytes
/
unit.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "main.h"
#include "hash.h"
#include "list.h"
#include "io.h"
#include "stack.h"
/*
* These are primative unit tests.
*/
extern stack_t STACK;
void test_stack(void) {
int i;
char buf[256];
push(&STACK,"one");
push(&STACK,"two");
push(&STACK,"three");
printf("%s\n",pop(&STACK));
printf("%s\n",pop(&STACK));
printf("%s\n",pop(&STACK));
for(i=0;i<26;i++) {
sprintf(buf,"%d",i);
push(&STACK,buf);
}
}
void test_hash(void) {
f("this",0);
f("this",0);
f("is",0);
f("a",0);
f("test",0);
}
void test_list(void) {
int i;
int iArray[] = {0,1,2,3,4,5,6,7,8,9};
list_t *pList;
node_t *pNode;
// list unit tests
pList = init_list();
if (NULL == pList) {
fprintf(stderr, "error in list create.\n");
exit(-1);
}
i=0;
while(i<10) {
append(pList,&iArray[i]);
i++;
}
pNode=pList->pFirst;
while(NULL != pNode) {
printf("list item => %d\n",*(int*) pNode->pData);
pNode = pNode->pNext;
}
}