diff options
| author | mo khan <mo.khan@gmail.com> | 2020-09-07 15:38:18 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-09-07 15:38:18 -0600 |
| commit | 4d6aa98bde0ce346053ee9b403449e3af53d269e (patch) | |
| tree | 33169eb7b87b72ffab2b0bdf91f738e9a41906e5 /src/03 | |
| parent | c942a5062c9a0b853cd350f0fa3f914efc90935b (diff) | |
Ensure that 128 vertices can be added to graph
Diffstat (limited to 'src/03')
| -rw-r--r-- | src/03/graph.c | 3 | ||||
| -rw-r--r-- | src/03/graph.h | 2 | ||||
| -rw-r--r-- | src/03/graph_test.c | 17 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/03/graph.c b/src/03/graph.c index fbd8677..0467e8b 100644 --- a/src/03/graph.c +++ b/src/03/graph.c @@ -1,5 +1,6 @@ #include "graph.h" #include <stdlib.h> +#include <stdio.h> Vertex *vertex_initialize(char label) { Vertex *item = malloc(sizeof(Vertex)); @@ -9,7 +10,7 @@ Vertex *vertex_initialize(char label) { Graph *graph_initialize(void) { Graph *item = malloc(sizeof(Graph)); - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 128; ++i) item->vertices[i] = NULL; return item; } diff --git a/src/03/graph.h b/src/03/graph.h index 65f01f5..d295490 100644 --- a/src/03/graph.h +++ b/src/03/graph.h @@ -3,7 +3,7 @@ typedef struct { } Vertex; typedef struct { - Vertex *vertices[256]; + Vertex *vertices[128]; } Graph; Graph *graph_initialize(void); diff --git a/src/03/graph_test.c b/src/03/graph_test.c index 44a8715..27af514 100644 --- a/src/03/graph_test.c +++ b/src/03/graph_test.c @@ -6,10 +6,12 @@ Ensure(three_equals_three) { assert_that(3, is_equal_to(3)); } -Ensure(initialize_returns_a_new_vertex) { +Ensure(initialize_returns_a_new_graph) { Graph *graph = graph_initialize(); assert_that(graph, is_not_equal_to(NULL)); + for (int i = 0; i < 128; ++i) + assert_that(graph->vertices[i], is_equal_to(NULL)); } Ensure(add_vertex_returns_a_new_vertex) { @@ -21,14 +23,25 @@ Ensure(add_vertex_returns_a_new_vertex) { assert_that(graph->vertices[(int)label], is_equal_to(a)); } +Ensure(add_vertex_adds_max_number_of_verticies_to_graph) { + Graph *graph = graph_initialize(); + + for (int i = 0; i < 128; ++i) { + Vertex *item = graph_add_vertex(graph, (char)i); + assert_that(item, is_not_equal_to(NULL)); + assert_that(graph->vertices[i], is_equal_to(item)); + } +} + TestSuite *graph_tests() { TestSuite *x = create_test_suite(); add_test(x, three_equals_three); - add_test(x, initialize_returns_a_new_vertex); + add_test(x, initialize_returns_a_new_graph); add_test(x, add_vertex_returns_a_new_vertex); + add_test(x, add_vertex_adds_max_number_of_verticies_to_graph); return x; } |
