-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_graphs.rb
112 lines (97 loc) · 2.67 KB
/
test_graphs.rb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require_relative "graphs"
require_relative "dsl"
require "test/unit"
class TestGraphs < Test::Unit::TestCase
@@did_setup = false
def setup
super
return if @@did_setup
@@did_setup = true
GraphConfig::GraphSettings.configure do
track_performance true
end
GraphConfig.configure do
config Graph do
id :dag_has_cycle_true
directed true
algorithm :has_cycle?
node_count 7
edges [[0,1],[0,2],[1,4],[2,3],[3,1],[3,5],[4,6],[5,4],[6,5]]
expected_result true
end
config Graph do
id :dag_has_cycle_false
directed true
algorithm :has_cycle?
node_count 5
edges [[0,1],[0,2],[2,3],[3,4],[4,1]]
expected_result false
end
config Graph do
id :uag_has_cycle_false
directed false
algorithm :has_cycle?
node_count 7
edges [[0,1],[0,2],[2,3],[2,4],[4,5],[4,6]]
expected_result false
end
config Graph do
id :uag_has_cycle_true
directed false
algorithm :has_cycle?
node_count 4
edges [[0,1],[0,2],[1,3],[2,3]]
expected_result true
end
config Graph do
id :topo_sort
directed true
algorithm :topological_sort
node_count 7
edges [[0,2],[0,5],[1,3],[1,6],[2,4],[3,5],[5,2],[5,4],[6,2]]
expected_result [1, 6, 3, 0, 5, 2, 4]
end
end
end
def test_settings
values = GraphConfig::GraphSettings.settings_values
track_performance = values[:track_performance]
assert_equal(track_performance, true)
end
# tests
# no expected value
# raise exception when unknown attrs
# undirected graphs
# all variations of build*
def test_graph_builds
graph = GraphConfig.build(:dag_has_cycle_true)
assert_not_nil(graph)
# add validation tests between proxy values and graph values
graphs = GraphConfig.build_all()
assert_equal(graphs.size, GraphConfig.registry.size)
end
def test_attribute_whitelist
# throw exception instead of ignoring unknown attrs
end
def test_graph_run_dag_has_cycle
assert_nothing_raised do
GraphConfig.build(:dag_has_cycle_true).run_algorithm
end
assert_nothing_raised do
GraphConfig.build(:dag_has_cycle_false).run_algorithm
end
end
def test_graph_run_uag_has_cycle
assert_nothing_raised do
GraphConfig.build(:uag_has_cycle_false).run_algorithm
end
assert_nothing_raised do
GraphConfig.build(:uag_has_cycle_true).run_algorithm
end
end
def test_graph_run_topo_sort
assert_nothing_raised do
GraphConfig.build(:topo_sort).run_algorithm
end
end
end