diff --git a/set/set.go b/set/set.go index 172482cd..563bb43c 100644 --- a/set/set.go +++ b/set/set.go @@ -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 diff --git a/set/set_test.go b/set/set_test.go index ea2d9d50..a4bef5c0 100644 --- a/set/set_test.go +++ b/set/set_test.go @@ -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]()