summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-09-07 18:55:03 -0600
committermo khan <mo.khan@gmail.com>2020-09-07 18:55:03 -0600
commit81f845facd2c911846f7bffe1f7ecfebd8039f78 (patch)
tree389d76acd6546e18a03ec70daefe5e81bf7daace
parent373fbfd822be53d76c861118d5fa60300d223d6b (diff)
test: add test to check if vertices are connected
-rw-r--r--src/03/graph.c4
-rw-r--r--src/03/graph.h1
-rw-r--r--src/03/graph_test.c23
3 files changed, 18 insertions, 10 deletions
diff --git a/src/03/graph.c b/src/03/graph.c
index 1e67202..db76be1 100644
--- a/src/03/graph.c
+++ b/src/03/graph.c
@@ -24,3 +24,7 @@ Vertex *graph_add_vertex(Graph *graph, char label) {
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;
+}
diff --git a/src/03/graph.h b/src/03/graph.h
index 95c96d8..e4f7c1c 100644
--- a/src/03/graph.h
+++ b/src/03/graph.h
@@ -12,3 +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);
diff --git a/src/03/graph_test.c b/src/03/graph_test.c
index 7a04a5b..c01db7d 100644
--- a/src/03/graph_test.c
+++ b/src/03/graph_test.c
@@ -2,10 +2,6 @@
#include <cgreen/cgreen.h>
#include <string.h>
-Ensure(three_equals_three) {
- assert_that(3, is_equal_to(3));
-}
-
Ensure(initialize_returns_a_new_graph) {
Graph *graph = graph_initialize();
@@ -46,17 +42,24 @@ Ensure(add_edge_connects_two_vertices) {
assert_that(graph->edges['b']['a'], is_equal_to(false));
}
-TestSuite *graph_tests() {
- TestSuite *x = create_test_suite();
+Ensure(connected_returns_true) {
+ Graph *graph = graph_initialize();
+ Vertex *a = graph_add_vertex(graph, 'a');
+ Vertex *b = graph_add_vertex(graph, 'b');
- add_test(x, three_equals_three);
+ graph_add_edge(graph, a, b);
- add_test(x, initialize_returns_a_new_graph);
+ assert_that(graph_connected(graph, a, b), is_equal_to(true));
+}
- add_test(x, add_vertex_returns_a_new_vertex);
- add_test(x, add_vertex_adds_max_number_of_verticies_to_graph);
+TestSuite *graph_tests() {
+ TestSuite *x = create_test_suite();
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, initialize_returns_a_new_graph);
return x;
}