summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-21 23:03:29 +0800
committerruki <[email protected]>2025-04-08 15:31:54 +0800
commit741da62196bcb64c88e386f1a769462211c63b4e (patch)
treec381546976a29ac9a642a18e241bc7de9874d7a3 /tests/modules
parent7e949212c4aff661f6dfd6234af7fd021a8568e3 (diff)
add queue and improve graph
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/graph/test.lua8
-rw-r--r--tests/modules/queue/test.lua35
2 files changed, 39 insertions, 4 deletions
diff --git a/tests/modules/graph/test.lua b/tests/modules/graph/test.lua
index 4bbefe069..33e1f3fa7 100644
--- a/tests/modules/graph/test.lua
+++ b/tests/modules/graph/test.lua
@@ -1,6 +1,6 @@
import("core.base.graph")
-function test_topological_sort(t)
+function test_topo_sort(t)
local edges = {
{0, 5},
{0, 2},
@@ -18,7 +18,7 @@ function test_topological_sort(t)
for _, e in ipairs(edges) do
dag:add_edge(e[1], e[2])
end
- local order_path = dag:topological_sort()
+ local order_path = dag:topo_sort()
local orders = {}
for i, v in ipairs(order_path) do
orders[v] = i
@@ -28,7 +28,7 @@ function test_topological_sort(t)
end
dag = dag:reverse()
- order_path = dag:topological_sort()
+ order_path = dag:topo_sort()
orders = {}
for i, v in ipairs(order_path) do
orders[v] = i
@@ -53,7 +53,7 @@ function test_find_cycle(t)
local cycle = dag:find_cycle()
t:are_equal(cycle, {1, 6, 0})
- local _, has_cycle = dag:topological_sort()
+ local _, has_cycle = dag:topo_sort()
t:require(has_cycle)
end
diff --git a/tests/modules/queue/test.lua b/tests/modules/queue/test.lua
new file mode 100644
index 000000000..b577e04c9
--- /dev/null
+++ b/tests/modules/queue/test.lua
@@ -0,0 +1,35 @@
+import("core.base.queue")
+
+function test_push(t)
+ local d = queue.new()
+ d:push(1)
+ d:push(2)
+ d:push(3)
+ d:push(4)
+ d:push(5)
+ t:are_equal(d:first(), 1)
+ t:are_equal(d:last(), 5)
+ local idx = 1
+ for item in d:items() do
+ t:are_equal(item, idx)
+ idx = idx + 1
+ end
+end
+
+function test_pop(t)
+ local d = queue.new()
+ d:push(1)
+ d:push(2)
+ d:push(3)
+ d:push(4)
+ d:push(5)
+ d:pop()
+ t:are_equal(d:first(), 2)
+ t:are_equal(d:last(), 5)
+ local idx = 2
+ for item in d:items() do
+ t:are_equal(item, idx)
+ idx = idx + 1
+ end
+end
+