-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
68 lines (59 loc) · 1.81 KB
/
test.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
#include <stdio.h>
#include <assert.h>
#include "clist.h"
int main() {
const char *names[] = {"Phomolo", "Thekgo", "Puleng", "Tebatso", "Molemo", "Tshepo", "Isaac"};
//create the table/array to hold the list.
puts("Creating list...");
table_t t = create();
puts("Adding 15 elements to our list...");
for(int i=0;i<7;i++) {
append(t, S, &names[i]);
append(t, I, &i);
}
double pi = 3.1415;
append(t, D, &pi); //Add pi to the end of the list.
assert(15 == length(t));
printf("Testing length(): %d\n", length(t));
puts("\nTesting print() function");
print(t);
puts("\nTesting sort()...");
sort_asc(t);
print(t);
puts("\nTesting is_in()...");
printf("%f is in list @ %d\n%s is in list @ %d\n",pi,is_in(t,D,&pi),names[0], is_in(t,S,&names[0]));
const char *str[] = {"notinlist","test"};
assert(-1==is_in(t,S,&str[0]));
assert(-1==is_in(t,S,&str[1]));
printf("is_in(%s) returned: %d\nis_in(%s) returned: %d\n",str[0],is_in(t,S,&str[0]),str[1],is_in(t,S,&str[1]));
int i = 4;
puts("\nTesting Pop() by pop()'ing 4 items from the end of the list");
while(i>0){
pop(t);
i--;
}
assert(11 == length(t));
printf("After pop()'ing 4 items length = %d\n",length(t));
print(t);
int z3=3, z2=2;
puts("\nTesting remove_item()...");
remove_item(t,S,&names[6]);
printf("length of new list after removing %s : %d\n",names[6],length(t));
print(t);
printf("%s is @ %d\n",names[4],is_in(t,S,&names[4]));
remove_item(t,I,&z3);
remove_item(t,I,&z2);
assert(8 == length(t));
printf("%s is now @ %d\n",names[4],is_in(t,S,&names[4]));
print(t);
puts("\nTesting sort(): sorting list...");
sort_asc(t);
print(t);
printf("\nTesting prepend(), by prepend()'ing : %s\n",names[5]);
prepend(t,S,&names[5]);
//prepend(t,S,&names[6]);
print(t);
puts("\n[!]Done[!]\nFree()'ing/liberating the list...");
libr8(t);
return 0;
}