Created
May 16, 2022 06:44
-
-
Save sausheong/0a54598682912d48abd850e593d7ba5f to your computer and use it in GitHub Desktop.
generics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestSet(t *testing.T) { | |
set := NewSet() | |
set.Add("the") | |
set.Add("quick") | |
set.Add("brown") | |
set.Add("fox") | |
set.Add("the") | |
if !set.Has("quick") { | |
t.Error("set doesn't have quick") | |
} | |
list := set.List() | |
sort.Slice(list, func(i, j int) bool { | |
return strings.Compare(list[i], list[j]) == -1 | |
}) | |
if !reflect.DeepEqual(list, []string{"brown", "fox", "quick", "the"}) { | |
t.Error(list) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment