Skip to content

Commit

Permalink
Merge pull request #286 from skitt/set-equal
Browse files Browse the repository at this point in the history
Ensure set.Equal() compares the two set lengths
  • Loading branch information
k8s-ci-robot authored Jul 11, 2023
2 parents 9f67429 + ecd9d48 commit 3019533
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s Set[E]) Difference(s2 Set[E]) Set[E] {
// Equal returns true if and only if s1 is equal (as a set) to s2.
// Two sets are equal if their membership is identical.
func (s Set[E]) Equal(s2 Set[E]) bool {
return s.Len() == s.Len() && s.IsSuperset(s2)
return s.Len() == s2.Len() && s.IsSuperset(s2)
}

type sortableSlice[E ordered] []E
Expand Down
6 changes: 6 additions & 0 deletions set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,17 @@ func TestStringSetEquals(t *testing.T) {
if a.Equal(b) {
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
}
if b.Equal(a) {
t.Errorf("Expected to be not-equal: %v vs %v", b, a)
}

b = New[string]("1", "2", "")
if a.Equal(b) {
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
}
if b.Equal(a) {
t.Errorf("Expected to be not-equal: %v vs %v", b, a)
}

// Check for equality after mutation
a = New[string]()
Expand Down

0 comments on commit 3019533

Please sign in to comment.