| 30 | typename graph |
| 31 | > |
| 32 | void graph_test ( |
| 33 | ) |
| 34 | /*! |
| 35 | requires |
| 36 | - graph is an implementation of graph/graph_kernel_abstract.h |
| 37 | is instantiated with int |
| 38 | ensures |
| 39 | - runs tests on graph for compliance with the specs |
| 40 | !*/ |
| 41 | { |
| 42 | |
| 43 | print_spinner(); |
| 44 | |
| 45 | COMPILE_TIME_ASSERT(is_graph<graph>::value); |
| 46 | |
| 47 | graph a, b; |
| 48 | dlib::set<unsigned long>::compare_1b_c s; |
| 49 | |
| 50 | DLIB_TEST(graph_contains_length_one_cycle(a) == false); |
| 51 | DLIB_TEST(graph_contains_undirected_cycle(a) == false); |
| 52 | |
| 53 | DLIB_TEST(a.number_of_nodes() == 0); |
| 54 | |
| 55 | a.set_number_of_nodes(5); |
| 56 | DLIB_TEST(graph_is_connected(a) == false); |
| 57 | DLIB_TEST(graph_contains_undirected_cycle(a) == false); |
| 58 | DLIB_TEST(a.number_of_nodes() == 5); |
| 59 | DLIB_TEST(graph_contains_length_one_cycle(a) == false); |
| 60 | |
| 61 | for (int i = 0; i < 5; ++i) |
| 62 | { |
| 63 | a.node(i).data = i; |
| 64 | DLIB_TEST(a.node(i).index() == (unsigned int)i); |
| 65 | } |
| 66 | |
| 67 | a.remove_node(1); |
| 68 | |
| 69 | DLIB_TEST(a.number_of_nodes() == 4); |
| 70 | |
| 71 | |
| 72 | // make sure that only the number with data == 1 was removed |
| 73 | int count = 0; |
| 74 | for (int i = 0; i < 4; ++i) |
| 75 | { |
| 76 | count += a.node(i).data; |
| 77 | DLIB_TEST(a.node(i).number_of_neighbors() == 0); |
| 78 | DLIB_TEST(a.node(i).index() == (unsigned int)i); |
| 79 | } |
| 80 | |
| 81 | DLIB_TEST(count == 9); |
| 82 | |
| 83 | |
| 84 | a.add_edge(1,1); |
| 85 | DLIB_TEST(graph_contains_length_one_cycle(a) == true); |
| 86 | DLIB_TEST(graph_contains_undirected_cycle(a) == true); |
| 87 | DLIB_TEST(a.has_edge(1,1)); |
| 88 | DLIB_TEST(a.node(1).number_of_neighbors() == 1); |
| 89 |
nothing calls this directly
no test coverage detected