diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 01:54:51 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 01:54:51 +0000 |
| commit | 98623f2fdd63232edf0ebab1b9680cf4e33e6f10 (patch) | |
| tree | 46e05b4953ea873bc5e52339a333f7911fc22867 /tests/std/test_queue.zc | |
| parent | 8cb7089b2eb09d40d9497cea40d088d94676a8c6 (diff) | |
More docs, and a few improvements for the standard library
Diffstat (limited to 'tests/std/test_queue.zc')
| -rw-r--r-- | tests/std/test_queue.zc | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/tests/std/test_queue.zc b/tests/std/test_queue.zc index 131eb05..d8895b8 100644 --- a/tests/std/test_queue.zc +++ b/tests/std/test_queue.zc @@ -1,15 +1,15 @@ import "std/queue.zc" test "Queue Push/Pop" { - print "Testing Queue Push/Pop"; + println "Testing Queue Push/Pop"; var queue = Queue<i32>::new(); defer queue.free(); - print "Popping on an empty queue without pushing anything prior" + println "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..." + println "Pushing in three values..." queue.push(123); queue.push(456); queue.push(789); @@ -23,13 +23,13 @@ test "Queue Push/Pop" { 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" + println "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 Length and Clear" { - print "Testing Queue clear"; + println "Testing Queue clear"; var queue = Queue<i32>::new(); defer queue.free(); @@ -43,7 +43,7 @@ test "Queue Length and Clear" { } test "Queue Clone" { - print "Testing Queue Cloning"; + println "Testing Queue Cloning"; var queue = Queue<i32>::new(); defer queue.free(); queue.push(123); @@ -60,3 +60,43 @@ test "Queue Clone" { v = queue.pop(); assert(v.is_none(), "v should not have a valid value"); } + +test "Queue Ring Buffer (Advanced)" { + var q = Queue<int>::new(); + + println "Fill slightly" + q.push(1); + q.push(2); + q.push(3); + assert(*q.pop().unwrap_ref() == 1); + + println "Pushing until capacity (assume 8)" + q.push(4); q.push(5); q.push(6); q.push(7); q.push(8); q.push(9); + + println "Popping some to advance head" + assert(*q.pop().unwrap_ref() == 2); + assert(*q.pop().unwrap_ref() == 3); + + println "Pushing to wrap tail" + q.push(10); + q.push(11); + + while (!q.is_empty()) { + q.pop(); + } + + println "Testing clear" + q.push(100); + q.clear(); + assert(q.is_empty()); + + println "Large scale test" + for (var i = 0; i < 100; i=i+1) { + q.push(i); + } + for (var i = 0; i < 100; i=i+1) { + assert(*q.pop().unwrap_ref() == i); + } + + q.free(); +} |
