improved xslices tests

This commit is contained in:
kim 2024-11-08 14:35:23 +00:00
parent 7b26b62a04
commit 91056bca79

View file

@ -33,6 +33,9 @@ func TestGrowJust(t *testing.T) {
for _, g := range []int{0, 2, 4, 8, 16, 32, 64} { for _, g := range []int{0, 2, 4, 8, 16, 32, 64} {
s2 := xslices.GrowJust(s, g) s2 := xslices.GrowJust(s, g)
// Slice length should not be different.
assert.Equal(t, len(s), len(s2))
switch { switch {
// If slice already has capacity for // If slice already has capacity for
// 'g' then it should not be changed. // 'g' then it should not be changed.
@ -58,6 +61,9 @@ func TestAppendJust(t *testing.T) {
toAppend := make([]int, a) toAppend := make([]int, a)
s2 := xslices.AppendJust(s, toAppend...) s2 := xslices.AppendJust(s, toAppend...)
// Slice length should be as expected.
assert.Equal(t, len(s2), len(s)+a)
switch { switch {
// If slice already has capacity for // If slice already has capacity for
// 'toAppend' then it should not change. // 'toAppend' then it should not change.
@ -68,7 +74,7 @@ func TestAppendJust(t *testing.T) {
// have capacity for original length // have capacity for original length
// plus extra elements, NOTHING MORE. // plus extra elements, NOTHING MORE.
default: default:
assert.Equal(t, cap(s2), len(s)+len(toAppend)) assert.Equal(t, cap(s2), len(s)+a)
} }
} }
} }