From bcc8f03b95c35e8988f90e5fd3b58112fd634016 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Fri, 11 Apr 2025 16:51:37 -0700 Subject: Fix a bug in PopAll when the queue is full --- deque_test.go | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'deque_test.go') 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) + } + }) } } -- cgit v1.3.1