MCPcopy Create free account
hub / github.com/davisking/dlib / directed_graph_test

Function directed_graph_test

dlib/test/directed_graph.cpp:33–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

print_spinnerFunction · 0.85
graph_is_connectedFunction · 0.85
create_moral_graphFunction · 0.85
create_join_treeFunction · 0.85
is_join_treeFunction · 0.85
is_cliqueFunction · 0.85
is_maximal_cliqueFunction · 0.85
number_of_childrenMethod · 0.80

Tested by

no test coverage detected