diff options
| author | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 19:35:12 +0800 |
|---|---|---|
| committer | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 19:35:12 +0800 |
| commit | e8ef3454880b92a5485a339b3b6fe7b64cfe5305 (patch) | |
| tree | 7e82fc6cb9ef2f81919a383ff83c6b79acd6a764 /tests/std | |
| parent | 8144aef45d5db22ab2895b41448cd76bf01e05cc (diff) | |
Add length, clear, is_empty to Stack and Queue
Diffstat (limited to 'tests/std')
| -rw-r--r-- | tests/std/test_queue.zc | 14 | ||||
| -rw-r--r-- | tests/std/test_stack.zc | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/std/test_queue.zc b/tests/std/test_queue.zc index 4d40c42..131eb05 100644 --- a/tests/std/test_queue.zc +++ b/tests/std/test_queue.zc @@ -28,6 +28,20 @@ test "Queue Push/Pop" { assert(v.is_none(), "v should not have a valid value"); } +test "Queue Length and Clear" { + print "Testing Queue clear"; + var queue = Queue<i32>::new(); + defer queue.free(); + + assert(queue.is_empty() && queue.length() == 0, "queue should be empty"); + + queue.push(123); + assert(!queue.is_empty() && queue.length() == 1, "queue should have 1 value"); + + queue.clear(); + assert(queue.is_empty() && queue.length() == 0, "queue should be empty"); +} + test "Queue Clone" { print "Testing Queue Cloning"; var queue = Queue<i32>::new(); diff --git a/tests/std/test_stack.zc b/tests/std/test_stack.zc index ecc9d3c..03e51a4 100644 --- a/tests/std/test_stack.zc +++ b/tests/std/test_stack.zc @@ -28,6 +28,20 @@ test "Stack Push/Pop" { assert(v.is_none(), "v should not have a valid value"); } +test "Stack Length and Clear" { + print "Testing Stack clear"; + var stack = Stack<i32>::new(); + defer stack.free(); + + assert(stack.is_empty() && stack.length() == 0, "Stack should be empty"); + + stack.push(123); + assert(!stack.is_empty() && stack.length() == 1, "Stack should have 1 value"); + + stack.clear(); + assert(stack.is_empty() && stack.length() == 0, "Stack should be empty"); +} + test "Stack Clone" { print "Testing Stack Cloning"; var stack = Stack<i32>::new(); |
