mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [queue] keep circular queues reusable after clear (#394)
This commit is contained in:
1 parent
8225b6d7d9
commit
fe4c81a677
2 files changed
+21
-3
No files matched your search
@@ -0,0 +1,19 @@
|
||||
package datastructure
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCircularQueueReuseAfterClear(t *testing.T) {
|
||||
queue := NewCircularQueue[int](3)
|
||||
queue.Enqueue(1)
|
||||
queue.Clear()
|
||||
if err := queue.Enqueue(2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if queue.Size() != 1 || queue.Front() != 2 {
|
||||
t.Error("cleared queue could not be reused")
|
||||
}
|
||||
zero := NewCircularQueue[int](0)
|
||||
if !zero.IsFull() || zero.Enqueue(1) == nil {
|
||||
t.Error("zero-capacity queue should reject an element")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user