viper-app/pkg/set_test.go

42 lines
563 B
Go
Raw Normal View History

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