mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [queue] check membership only in active slots (#390)
This commit is contained in:
1 parent
7c77aa00fb
commit
e2524f4498
3 files changed
+29
-4
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package datastructure
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestQueueContainActiveValues(t *testing.T) {
|
||||
array := NewArrayQueue[int](5)
|
||||
array.Enqueue(1)
|
||||
array.Enqueue(2)
|
||||
array.Dequeue()
|
||||
if array.Contain(1) || !array.Contain(2) {
|
||||
t.Error("array queue includes a dequeued value")
|
||||
}
|
||||
circular := NewCircularQueue[int](4)
|
||||
if circular.Contain(0) {
|
||||
t.Error("empty circular queue contains a zero value")
|
||||
}
|
||||
circular.Enqueue(1)
|
||||
circular.Enqueue(2)
|
||||
circular.Dequeue()
|
||||
circular.Enqueue(3)
|
||||
circular.Enqueue(4)
|
||||
if circular.Contain(0) || circular.Contain(1) || !circular.Contain(4) {
|
||||
t.Error("circular queue did not restrict its search to active values")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user