Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created May 16, 2022 06:49
Show Gist options
  • Save sausheong/2a0ac7bfe3dbb2e05f866cc8e1a1cf1b to your computer and use it in GitHub Desktop.
Save sausheong/2a0ac7bfe3dbb2e05f866cc8e1a1cf1b to your computer and use it in GitHub Desktop.
generics
func TestTSet(t *testing.T) {
set := NewTSet[string]()
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