diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-04-11 16:51:37 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-04-11 16:51:37 -0700 |
| commit | bcc8f03b95c35e8988f90e5fd3b58112fd634016 (patch) | |
| tree | a07e5254312bb04b3f4e78792c0a6c87f79662fa /deque_test.go | |
| parent | 43e0f85d803045a073e2c78063bd8bc944d0fe68 (diff) | |
| download | deque-bcc8f03b95c35e8988f90e5fd3b58112fd634016.tar.zst | |
Fix a bug in PopAll when the queue is full
Diffstat (limited to 'deque_test.go')
| -rw-r--r-- | deque_test.go | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/deque_test.go b/deque_test.go index 4f298e1..fede96b 100644 --- a/deque_test.go +++ b/deque_test.go @@ -260,17 +260,31 @@ func TestReset(t *testing.T) { func TestPopAll(t *testing.T) { t.Parallel() - q := From([]int{1, 2, 3}) - got := make([]int, 0, q.Len()) - for x := range q.PopAll() { - got = append(got, x) - } - if got, want := q.Len(), 0; got != want { - t.Errorf("Len() = %d, want %d", got, want) - } - want := []int{1, 2, 3} - if !slices.Equal(got, want) { - t.Errorf("PopAll() returned values %d, want %d", got, want) + for _, tc := range []struct { + desc string + content []int + }{{ + desc: "PopAll", + content: []int{1, 2, 3}, + }, { + desc: "PopAllEmpty", + content: make([]int, 0, 3), + }} { + t.Run(tc.desc, func(t *testing.T) { + t.Parallel() + + q := From(tc.content) + got := make([]int, 0, q.Len()) + for x := range q.PopAll() { + got = append(got, x) + } + if got, want := q.Len(), 0; got != want { + t.Errorf("Len() = %d, want %d", got, want) + } + if !slices.Equal(got, tc.content) { + t.Errorf("PopAll() returned values %d, want %d", got, tc.content) + } + }) } } |
