viper-app/pkg/set/set_test.go

42 lines
563 B
Go
Raw Normal View History

package set
2023-02-03 16:18:31 +08:00
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()
}
})
}