summaryrefslogtreecommitdiff
path: root/tests/std/test_queue.zc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/std/test_queue.zc')
-rw-r--r--tests/std/test_queue.zc52
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();
+}