Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created May 16, 2022 06:44
Show Gist options
  • Save sausheong/0a54598682912d48abd850e593d7ba5f to your computer and use it in GitHub Desktop.
Save sausheong/0a54598682912d48abd850e593d7ba5f to your computer and use it in GitHub Desktop.
generics
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