Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/graph.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_graph.lua')
-rw-r--r--test/test_graph.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_graph.lua b/test/test_graph.lua
index 3ae9e16..3967a85 100644
--- a/test/test_graph.lua
+++ b/test/test_graph.lua
@@ -134,4 +134,33 @@ function tests.test_bfs()
end
end
+function tests.test_cycle()
+ local n1 = graph.Node(1)
+ local n2 = graph.Node(2)
+ local n3 = graph.Node(3)
+ local n4 = graph.Node(4)
+ local cycle = graph.Graph()
+ cycle:add(graph.Edge(n1, n2))
+ cycle:add(graph.Edge(n1, n3))
+ cycle:add(graph.Edge(n2, n3))
+ cycle:add(graph.Edge(n3, n2))
+ cycle:add(graph.Edge(n2, n4))
+ cycle:add(graph.Edge(n3, n4))
+
+ tester:asserteq(cycle:hasCycle(), true, 'Graph is supposed to have cycle')
+
+ local n1 = graph.Node(1)
+ local n2 = graph.Node(2)
+ local n3 = graph.Node(3)
+ local n4 = graph.Node(4)
+ local nocycle = graph.Graph()
+ nocycle:add(graph.Edge(n1, n2))
+ nocycle:add(graph.Edge(n1, n3))
+ nocycle:add(graph.Edge(n2, n3))
+ nocycle:add(graph.Edge(n2, n4))
+ nocycle:add(graph.Edge(n3, n4))
+
+ tester:asserteq(nocycle:hasCycle(), false, 'Graph is not supposed to have cycle')
+end
+
return tester:add(tests):run()