Skip to content

Commit

Permalink
add test case for graph_insert_vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
weijieblog committed May 29, 2016
1 parent de84e48 commit 9370721
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 1 addition & 3 deletions graph/graph_destory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

void graph_destory(Graph *graph) {
AdjList *adjlist;

while (list_size(&graph->adjlists) > 0) {
if (list_remove(&graph->adjlists, list_head(&graph->adjlists), (void **)&adjlist) == 0) {
set_destory(&adjlist->adjacent);
if (graph != NULL)
if (graph->destory != NULL)
graph->destory(adjlist->vertex);
free(adjlist);
}
}

list_destory(&graph->adjlists);
memset(graph, 0, sizeof(Graph));
return;
Expand Down
4 changes: 2 additions & 2 deletions graph/graph_insert_vertex.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ int graph_insert_vertex(Graph *graph, const void *data) {

int result;

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

Expand Down
13 changes: 12 additions & 1 deletion graph/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ static int _match (const void *key1, const void *key2) {
}
int main (int argc, char **argv) {
Graph *testGraph1 = (Graph *)malloc(sizeof(Graph));
int testData1 = 0;
void *testPrt = &testData1;

graph_init(testGraph1, _match, NULL);
printf("'graph_init' is pass ? %d \n", testGraph1->vcount == 0 &&
testGraph1->ecount == 0 &&
testGraph1->destory == NULL);
testGraph1->destory == NULL);


graph_insert_vertex(testGraph1, testPrt);
printf("'graph_insert_vertex' is pass ? %d \n", testGraph1->vcount == 1 &&
testGraph1->ecount == 0 &&
testGraph1->destory == NULL);



graph_destory(testGraph1);
printf("'graph_destory' is pass ? %d \n", testGraph1->vcount == 0 &&
Expand Down

0 comments on commit 9370721

Please sign in to comment.