Skip to content

Commit

Permalink
add test coverage to set.go
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalhan committed Feb 26, 2024
1 parent e7106e6 commit 8c89a86
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ func TestStringSetEquals(t *testing.T) {
if !a.Equal(b) {
t.Errorf("Expected to be equal: %v vs %v", a, b)
}

a = New[string]("1", "2", "3")
b = New[string]("2", "1")
if a.Equal(b) {
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
}
// It is a set; duplicates are ignored
a = New[string]("1", "2")
b = New[string]("2", "2", "1")
if !a.Equal(b) {
t.Errorf("Expected to be equal: %v vs %v", a, b)
}

// Edge cases around empty sets / empty strings
a = New[string]()
b = New[string]()
Expand Down Expand Up @@ -369,3 +373,32 @@ func clearSetAndAdd[T ordered](s Set[T], a T) {
s.Clear()
s.Insert(a)
}

func TestPopAny(t *testing.T) {
a := New[string]("1", "2")
_, popped := a.PopAny()
if !popped {
t.Errorf("got len(%d): wanted 1", a.Len())
}
_, popped = a.PopAny()
if !popped {
t.Errorf("got len(%d): wanted 0", a.Len())
}
zeroVal, popped := a.PopAny()
if popped {
t.Errorf("got len(%d): wanted 0", a.Len())
}
if zeroVal != "" {
t.Errorf("should have gotten zero value when popping an empty set")
}
}

func TestClone(t *testing.T) {
a := New[string]("1", "2")
a.Insert("3")

got := a.Clone()
if !reflect.DeepEqual(got, a) {
t.Errorf("Expected to be equal: %v vs %v", got, a)
}
}

0 comments on commit 8c89a86

Please sign in to comment.