pkg/set/set_test.go
2023-09-18 15:58:52 +08:00

42 lines
563 B
Go

package set
import (
"testing"
)
func TestSet(t *testing.T) {
set := NewSet(4)
keys := []string{
"1", "2", "3", "something",
}
t.Run("SetAddItem", func(t *testing.T) {
for _, key := range keys {
set.Set(key)
}
if len(set) != len(keys) {
t.Fatal()
}
})
t.Run("SetHasItem", func(t *testing.T) {
var has bool
for _, key := range keys {
has = set.Has(key)
if !has {
t.Fatal()
}
}
})
t.Run("SetDelItem", func(t *testing.T) {
for _, key := range keys {
set.Del(key)
}
if len(set) != 0 {
t.Fatal()
}
})
}