Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deque.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (q *Deque[T]) Copy(src Deque[T]) int {
q.Grow(src.Len())
n := src.CopyOutSlice(q.buf)
q.count = n
q.tail = n
q.tail = n & (len(q.buf) - 1) // bitwise modulus
q.head = 0
return n
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func (q *Deque[T]) CopyInSlice(in []T) {
}
n := copy(q.buf, in)
q.count = n
q.tail = n
q.tail = n & (len(q.buf) - 1) // bitwise modulus
q.head = 0
}

Expand Down
28 changes: 28 additions & 0 deletions deque_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,34 @@ func TestCopy(t *testing.T) {
}
}

func TestClearAndPushBack(t *testing.T) {
q := &Deque[int]{}
in := make([]int, minCapacity)
q.Clear()
for i := range in {
q.PushBack(in[i])
}
q.PopFront()
q.PushBack(17)
}

func TestCopyPanic(t *testing.T) {
var q1, q2 Deque[int]
in := make([]int, minCapacity)
q1.CopyInSlice(in)
q2.Copy(q1)
q2.PopFront()
q2.PushBack(17)
}

func TestCopyInSlicePanic(t *testing.T) {
var q Deque[int]
in := make([]int, minCapacity)
q.CopyInSlice(in)
q.PopFront()
q.PushBack(17)
}

func assertPanics(t *testing.T, name string, f func()) {
defer func() {
if r := recover(); r == nil {
Expand Down
Loading