Skip to content

Commit

Permalink
add test case for graph_remove_edge
Browse files Browse the repository at this point in the history
  • Loading branch information
weijieblog committed Jun 1, 2016
1 parent c86097b commit 86a645d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
18 changes: 18 additions & 0 deletions graph/graph_remove_edge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "graph.h"
int graph_remove_edge(Graph *graph, void *data1, void **data2) {
ListElm *element, *temp;

for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) {
if (graph->match(data1, ((AdjList *)list_data(element))->vertex))
break;
}

if (element == NULL)
return -1;

if (set_remove(&((AdjList *)list_data(element))->adjacent, data2) != 0)
return -1;

graph->ecount--;
return 0;
}
1 change: 0 additions & 1 deletion graph/graph_remove_vertex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ int graph_remove_vertex(Graph *graph, void **data) {
ListElm *element, *temp;
AdjList *adjlist;
int found;
int test = 0;
found = 0;

for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) {
Expand Down
14 changes: 12 additions & 2 deletions graph/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,22 @@ int main (int argc, char **argv) {
testPtr2 = &testData2;
graph_insert_edge(testGraph1, testPtr1, testPtr2);
printf("'graph_insert_edge' is pass ? %d \n", testGraph1->vcount == 3 &&
testGraph1->ecount == 1);
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);
testGraph1->ecount == 1 &&
*(int *)testPtr2 == 2);


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_destory(testGraph1);
Expand Down
2 changes: 1 addition & 1 deletion graph/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ setObjects = ../set/set_init.o \
../set/set_remove.o \
../set/set_union.o

graphObjects = main.o graph_init.o graph_destory.o graph_insert_vertex.o graph_insert_edge.o graph_remove_vertex.o
graphObjects = main.o graph_init.o graph_destory.o graph_insert_vertex.o graph_insert_edge.o graph_remove_vertex.o graph_remove_edge.o

objects = $(listsObjects) $(setObjects) $(graphObjects)

Expand Down

0 comments on commit 86a645d

Please sign in to comment.