github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xcontainer/set/set_test.go (about) 1 package set 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestIntSet(t *testing.T) { 10 t.Run("getset", func(t *testing.T) { 11 set := IntSet{} 12 require.Equal(t, true, set.Insert(1), "first putting 1 success") 13 require.Equal(t, true, set.Insert(2), "first putting 2 success") 14 require.Equal(t, false, set.Insert(1), "second putting 1 failed") 15 require.Equal(t, true, set.Has(1), "set has 1") 16 require.Equal(t, true, set.Has(2), "set dose't has 3") 17 }) 18 } 19 20 func TestStringHashSet(t *testing.T) { 21 t.Run("getset", func(t *testing.T) { 22 set := NewStringHashSet("1", "2", "3", "4", "5", "1") 23 require.Equal(t, 5, set.Size(), "set contains 5 elements") 24 require.Equal(t, true, set.Contains("2"), "set contains 2") 25 require.Equal(t, false, set.Contains("6"), "set not contains 6") 26 }) 27 } 28 29 func TestStringBtreeSet(t *testing.T) { 30 t.Run("getset", func(t *testing.T) { 31 set := NewStringBtreeSet("1", "2", "3", "4", "5", "1") 32 require.Equal(t, 5, set.Size(), "set contains 5 elements") 33 require.Equal(t, true, set.Contains("2"), "set contains 2") 34 require.Equal(t, false, set.Contains("6"), "set not contains 6") 35 }) 36 }