github.com/koko1123/flow-go-1@v0.29.6/utils/slices/slices_test.go (about) 1 package slices_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/koko1123/flow-go-1/utils/slices" 9 ) 10 11 // TestSliceContainsElement tests that the StringSliceContainsElement function returns true if the string slice contains the element. 12 func TestSliceContainsElement(t *testing.T) { 13 a := []string{"a", "b", "c"} 14 15 require.True(t, slices.StringSliceContainsElement(a, "a")) 16 require.True(t, slices.StringSliceContainsElement(a, "b")) 17 require.True(t, slices.StringSliceContainsElement(a, "c")) 18 require.False(t, slices.StringSliceContainsElement(a, "d")) 19 } 20 21 // TestAreStringSlicesEqual tests that the AreStringSlicesEqual function returns true if the string slices are equal. 22 func TestAreStringSlicesEqual(t *testing.T) { 23 a := []string{"a", "b", "c"} 24 b := []string{"a", "b", "c"} 25 c := []string{"a", "b", "c", "d"} 26 d := []string{"a", "b", "d"} 27 28 require.True(t, slices.AreStringSlicesEqual(a, b)) 29 require.False(t, slices.AreStringSlicesEqual(a, c)) 30 require.False(t, slices.AreStringSlicesEqual(a, d)) 31 } 32 33 // TestAreStringSlicesEqual_DuplicateElements tests that the AreStringSlicesEqual function works with duplicate elements. 34 func TestAreStringSlicesEqual_DuplicateElements(t *testing.T) { 35 a := []string{"a", "a", "a", "a"} 36 b := []string{"a", "c", "d", "b"} 37 require.False(t, slices.AreStringSlicesEqual(a, b)) 38 39 a = []string{"a", "c", "d", "a"} 40 b = []string{"c", "a", "a", "d"} 41 require.True(t, slices.AreStringSlicesEqual(a, b)) 42 }