-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
64 lines (51 loc) · 2.43 KB
/
main.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
#include <stdio.h>
#include "graph.h"
static int _match (const void *key1, const void *key2) {
return (* (int *)key1) == (* (int *)key2);
}
int main (int argc, char **argv) {
Graph *testGraph1 = (Graph *)malloc(sizeof(Graph));
int testData1 = 0;
int testData2 = 1;
int testData3 = 2;
void *testPtr1;
void *testPtr2;
AdjList *testAdjlist1;
graph_init(testGraph1, _match, NULL);
printf("'graph_init' is pass ? %d \n", testGraph1->vcount == 0 &&
testGraph1->ecount == 0 &&
testGraph1->destory == NULL);
testPtr1 = &testData1;
graph_insert_vertex(testGraph1, testPtr1);
testPtr2 = &testData2;
graph_insert_vertex(testGraph1, testPtr2);
testPtr2 = &testData3;
graph_insert_vertex(testGraph1, testPtr2);
printf("'graph_insert_vertex' is pass ? %d \n", testGraph1->vcount == 3 &&
testGraph1->ecount == 0 &&
testGraph1->destory == NULL);
testPtr2 = &testData2;
graph_insert_edge(testGraph1, testPtr1, testPtr2);
printf("'graph_insert_edge' is pass ? %d \n", testGraph1->vcount == 3 &&
testGraph1->ecount == 1 &&
*(int *)testPtr2 == 1);
testPtr2 = &testData3;
graph_remove_vertex(testGraph1, &testPtr2);
printf("'graph_remove_vertex' is pass ? %d \n", testGraph1->vcount == 2 &&
testGraph1->ecount == 1 &&
*(int *)testPtr2 == 2);
testPtr2 = &testData2;
printf("'graph_is_adjacent' is pass ? %d \n", graph_is_adjacent(testGraph1, testPtr1, testPtr2));
testPtr2 = &testData2;
graph_remove_edge(testGraph1, testPtr1, &testPtr2);
printf("'graph_remove_edge' is pass ? %d \n", testGraph1->vcount == 2 &&
testGraph1->ecount == 0 &&
*(int *)testPtr2 == 1);
graph_adjlist(testGraph1, testPtr1, &testAdjlist1);
printf("'graph_adjlist' is pass ? %d \n", *(int *)testAdjlist1->vertex == 0);
graph_destory(testGraph1);
printf("'graph_destory' is pass ? %d \n", testGraph1->vcount == 0 &&
testGraph1->ecount == 0 &&
testGraph1->destory == 0);
return 0;
}