-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_test.go
More file actions
48 lines (36 loc) · 946 Bytes
/
buffer_test.go
File metadata and controls
48 lines (36 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) CattleCloud LLC
// SPDX-License-Identifier: BSD-3-Clause
package circlebuffer
import (
"testing"
"github.com/shoenig/test/must"
)
func testSequence[T any](t *testing.T, a Array[T], exp []T) {
t.Helper()
result := make([]T, 0, a.Size())
for item := range a.All() {
result = append(result, item)
}
must.Eq(t, exp, result)
}
func TestArray(t *testing.T) {
t.Parallel()
buf := New[string](3)
must.Empty(t, buf)
testSequence(t, buf, []string{})
buf.Insert("one")
must.Size(t, 1, buf)
testSequence(t, buf, []string{"one"})
buf.Insert("two")
must.Size(t, 2, buf)
testSequence(t, buf, []string{"one", "two"})
buf.Insert("three")
must.Size(t, 3, buf)
testSequence(t, buf, []string{"one", "two", "three"})
buf.Insert("four")
must.Size(t, 3, buf)
testSequence(t, buf, []string{"two", "three", "four"})
buf.Insert("five")
must.Size(t, 3, buf)
testSequence(t, buf, []string{"three", "four", "five"})
}