1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include "graph.h"
#include <cgreen/cgreen.h>
#include <string.h>
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) {
Graph *graph = graph_initialize();
char label = 'a';
Vertex *a = graph_add_vertex(graph, label);
assert_that(a, is_not_equal_to(NULL));
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));
}
}
Ensure(add_edge_connects_two_vertices) {
Graph *graph = graph_initialize();
graph_add_edge(
graph,
graph_add_vertex(graph, 'a'),
graph_add_vertex(graph, 'b')
);
assert_that(graph->edges['a']['b'], is_equal_to(true));
assert_that(graph->edges['b']['a'], is_equal_to(false));
}
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_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() {
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, has_edge_returns_true);
add_test(x, has_edge_returns_false);
add_test(x, initialize_returns_a_new_graph);
return x;
}
|