Skip to content

Commit

Permalink
Merge pull request #302 from logicalhan/set-tests
Browse files Browse the repository at this point in the history
add test coverage to set.go
  • Loading branch information
k8s-ci-robot authored May 2, 2024
2 parents 0849a56 + 8c89a86 commit fe8a2dd
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 fe8a2dd

Please sign in to comment.