summaryrefslogtreecommitdiff
path: root/tests/std/test_queue.zc
diff options
context:
space:
mode:
authorLam Wei Lun <weilun.lam@gmail.com>2026-01-21 02:46:02 +0800
committerLam Wei Lun <weilun.lam@gmail.com>2026-01-21 02:46:02 +0800
commit451e6b1fff77bccedccdb745e4ee56cbeef31b79 (patch)
treede5925e298a4373963c4bc96dd214aacf19b6a5c /tests/std/test_queue.zc
parent50e2dde008820ef5ae8bd502d2646e00e5139bc4 (diff)
Stack and Queue implementation and unit tests
Diffstat (limited to 'tests/std/test_queue.zc')
-rw-r--r--tests/std/test_queue.zc48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/std/test_queue.zc b/tests/std/test_queue.zc
new file mode 100644
index 0000000..4d40c42
--- /dev/null
+++ b/tests/std/test_queue.zc
@@ -0,0 +1,48 @@
+import "std/queue.zc"
+
+test "Queue Push/Pop" {
+ print "Testing Queue Push/Pop";
+ var queue = Queue<i32>::new();
+ defer queue.free();
+
+ print "Popping on an empty queue without pushing anything prior"
+ var v = queue.pop();
+ assert(v.is_none(), "v should not have a valid value");
+
+ print "Pushing in three values..."
+ queue.push(123);
+ queue.push(456);
+ queue.push(789);
+
+ v = queue.pop();
+ assert(v.is_some() && v.unwrap() == 123, "v's value should be 123");
+
+ v = queue.pop();
+ assert(v.is_some() && v.unwrap() == 456, "v's value should be 456");
+
+ v = queue.pop();
+ assert(v.is_some() && v.unwrap() == 789, "v's value should be 789");
+
+ print "Popping on an empty queue after pushing and popping three values"
+ v = queue.pop();
+ assert(v.is_none(), "v should not have a valid value");
+}
+
+test "Queue Clone" {
+ print "Testing Queue Cloning";
+ var queue = Queue<i32>::new();
+ defer queue.free();
+ queue.push(123);
+ var queue2 = queue.clone();
+ defer queue2.free();
+
+ var v = queue2.pop();
+ assert(v.is_some() && v.unwrap() == 123, "v's value should be 123");
+ v = queue2.pop();
+ assert(v.is_none(), "v should not have a valid value");
+
+ v = queue.pop();
+ assert(v.is_some() && v.unwrap() == 123, "v's value should be 123");
+ v = queue.pop();
+ assert(v.is_none(), "v should not have a valid value");
+}