diff options
| author | ruki <[email protected]> | 2023-09-30 00:36:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-09-30 00:36:53 +0800 |
| commit | 5a2c5c458af38dd90924f251d518b97ba2cf604b (patch) | |
| tree | 78ded54f7a54fd35ccd58c417a3178e18911dbca /tests/modules/graph/test.lua | |
| parent | c8f60856c4c998f3d4894524ba1576f8da43baa7 (diff) | |
find cycle in graph
Diffstat (limited to 'tests/modules/graph/test.lua')
| -rw-r--r-- | tests/modules/graph/test.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/modules/graph/test.lua b/tests/modules/graph/test.lua index cc0e16738..63095be12 100644 --- a/tests/modules/graph/test.lua +++ b/tests/modules/graph/test.lua @@ -38,3 +38,19 @@ function test_topological_sort(t) end end +function test_find_cycle(t) + local edges = { + {9, 1}, + {1, 6}, + {6, 0}, + {0, 1}, + {4, 5} + } + local dag = graph.new(true) + for _, e in ipairs(edges) do + dag:add_edge(e[1], e[2]) + end + local cycle = dag:find_cycle() + t:are_equal(cycle, {1, 6, 0}) +end + |
