Created
May 16, 2022 06:49
-
-
Save sausheong/2a0ac7bfe3dbb2e05f866cc8e1a1cf1b 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 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