sets/set_test.go

62 lines
948 B
Go
Raw Normal View History

2023-07-21 23:09:38 +02:00
package sets
import (
"testing"
"github.com/stretchr/testify/require"
)
func getTestSet(t *testing.T) *Set[int] {
t.Helper()
return &Set[int]{
store: map[int]struct{}{
0: {},
1: {},
2: {},
3: {},
4: {},
5: {},
6: {},
7: {},
8: {},
9: {},
},
}
}
func TestSetSize(t *testing.T) {
s := getTestSet(t)
require.Equal(t, 10, s.Size())
}
func TestSetContains(t *testing.T) {
s := getTestSet(t)
require.True(t, s.Contains(0))
require.False(t, s.Contains(10))
}
func TestSetInsert(t *testing.T) {
s := getTestSet(t)
require.True(t, s.Insert(0))
require.False(t, s.Insert(10))
require.Contains(t, s.store, 10)
}
func TestSetDelete(t *testing.T) {
s := getTestSet(t)
require.False(t, s.Delete(10))
require.True(t, s.Delete(0))
require.NotContains(t, s.store, 0)
}
func TestSetSlice(t *testing.T) {
s := getTestSet(t)
require.ElementsMatch(t, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, s.Slice())
}