diff options
| author | mo khan <mo.khan@gmail.com> | 2020-09-08 10:52:44 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-09-08 10:52:44 -0600 |
| commit | 6d195cdfdd34ee0755930b71058ed29832676583 (patch) | |
| tree | 0d6fdfddfdb84ddad636f1ed3d1f05ab6e07b687 /src | |
| parent | 81f845facd2c911846f7bffe1f7ecfebd8039f78 (diff) | |
refactor: rename connected to has_edge
Diffstat (limited to 'src')
| -rw-r--r-- | src/03/graph.c | 4 | ||||
| -rw-r--r-- | src/03/graph.h | 2 | ||||
| -rw-r--r-- | src/03/graph_test.c | 18 |
3 files changed, 18 insertions, 6 deletions
diff --git a/src/03/graph.c b/src/03/graph.c index db76be1..885a8ea 100644 --- a/src/03/graph.c +++ b/src/03/graph.c @@ -25,6 +25,6 @@ void graph_add_edge(Graph *graph, Vertex *a, Vertex *b) { graph->edges[a->label][b->label] = true; } -bool graph_connected(Graph *graph, Vertex *a, Vertex *b) { - return true; +bool graph_has_edge(Graph *graph, Vertex *a, Vertex *b) { + return graph->edges[a->label][b->label]; } diff --git a/src/03/graph.h b/src/03/graph.h index e4f7c1c..7e591c8 100644 --- a/src/03/graph.h +++ b/src/03/graph.h @@ -12,4 +12,4 @@ typedef struct { Graph *graph_initialize(void); Vertex *graph_add_vertex(Graph *graph, char label); void graph_add_edge(Graph *graph, Vertex *a, Vertex *b); -bool graph_connected(Graph *graph, Vertex *a, Vertex *b); +bool graph_has_edge(Graph *graph, Vertex *a, Vertex *b); diff --git a/src/03/graph_test.c b/src/03/graph_test.c index c01db7d..eb2cf7e 100644 --- a/src/03/graph_test.c +++ b/src/03/graph_test.c @@ -42,14 +42,25 @@ Ensure(add_edge_connects_two_vertices) { assert_that(graph->edges['b']['a'], is_equal_to(false)); } -Ensure(connected_returns_true) { +Ensure(has_edge_returns_true) { Graph *graph = graph_initialize(); Vertex *a = graph_add_vertex(graph, 'a'); Vertex *b = graph_add_vertex(graph, 'b'); graph_add_edge(graph, a, b); - assert_that(graph_connected(graph, a, b), is_equal_to(true)); + assert_that(graph_has_edge(graph, a, b), is_equal_to(true)); +} + +Ensure(has_edge_returns_false) { + Graph *graph = graph_initialize(); + Vertex *a = graph_add_vertex(graph, 'a'); + Vertex *b = graph_add_vertex(graph, 'b'); + Vertex *c = graph_add_vertex(graph, 'c'); + + graph_add_edge(graph, a, b); + + assert_that(graph_has_edge(graph, a, c), is_equal_to(false)); } TestSuite *graph_tests() { @@ -58,7 +69,8 @@ TestSuite *graph_tests() { add_test(x, add_edge_connects_two_vertices); add_test(x, add_vertex_adds_max_number_of_verticies_to_graph); add_test(x, add_vertex_returns_a_new_vertex); - add_test(x, connected_returns_true); + add_test(x, has_edge_returns_true); + add_test(x, has_edge_returns_false); add_test(x, initialize_returns_a_new_graph); return x; |
