aboutsummaryrefslogtreecommitdiffstats
path: root/heap/heap_test.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-04-15 17:24:29 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-04-15 17:24:29 -0700
commit9c9dc6b65c4b2775e0ba5686d43b0c224fd02836 (patch)
treece93473e6da18bcd4a289ebf3d630888892a849c /heap/heap_test.go
parentRemove some functions that weren't supposed to be there. (diff)
downloaddeque-9c9dc6b65c4b2775e0ba5686d43b0c224fd02836.tar.zst
Just deque
Diffstat (limited to 'heap/heap_test.go')
-rw-r--r--heap/heap_test.go72
1 files changed, 0 insertions, 72 deletions
diff --git a/heap/heap_test.go b/heap/heap_test.go
deleted file mode 100644
index afbc721..0000000
--- a/heap/heap_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package heap
-
-import (
- "cmp"
- "testing"
-)
-
-func verify(t *testing.T, h *Heap[int], i int) {
- t.Helper()
-
- n := h.Len()
- j1 := 2*i + 1
- j2 := 2*i + 2
- if j1 < n {
- if h.compare(h.buf[j1], h.buf[i]) < 0 {
- t.Errorf("heap invariant invalidated [%d] = %d > [%d] = %d", i, h.buf[i], j1, h.buf[j1])
- return
- }
- verify(t, h, j1)
- }
- if j2 < n {
- if h.compare(h.buf[j2], h.buf[i]) < 0 {
- t.Errorf("heap invariant invalidated [%d] = %d > [%d] = %d", i, h.buf[i], j1, h.buf[j2])
- return
- }
- verify(t, h, j2)
- }
-}
-
-func Test(t *testing.T) {
- t.Parallel()
-
- h := New(cmp.Compare[int])
- verify(t, h, 0)
- h.Grow(20)
- verify(t, h, 0)
-
- for i := 20; i > 10; i-- {
- h.Push(i)
- }
- verify(t, h, 0)
-
- for i := 10; i > 0; i-- {
- h.Push(i)
- verify(t, h, 0)
- }
-
- for i := 1; h.Len() > 0; i++ {
- x, ok := h.Pop()
- if !ok {
- t.Errorf("Pop() = false, want %d", i)
- }
- if i < 20 {
- h.Push(20 + i)
- }
- verify(t, h, 0)
- if x != i {
- t.Errorf("%d.th pop got %d; want %d", i, x, i)
- }
- }
-}
-
-func TestPopEmpty(t *testing.T) {
- t.Parallel()
-
- h := New(cmp.Compare[int])
- _, gotOk := h.Pop()
- const want = false
- if gotOk != want {
- t.Errorf("Pop() on empty heap = %t, want %t", gotOk, want)
- }
-}