Skip to content

Commit 3019533

Browse files
authored
Merge pull request #286 from skitt/set-equal
Ensure set.Equal() compares the two set lengths
2 parents 9f67429 + ecd9d48 commit 3019533

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

set/set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (s Set[E]) Difference(s2 Set[E]) Set[E] {
155155
// Equal returns true if and only if s1 is equal (as a set) to s2.
156156
// Two sets are equal if their membership is identical.
157157
func (s Set[E]) Equal(s2 Set[E]) bool {
158-
return s.Len() == s.Len() && s.IsSuperset(s2)
158+
return s.Len() == s2.Len() && s.IsSuperset(s2)
159159
}
160160

161161
type sortableSlice[E ordered] []E

set/set_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,17 @@ func TestStringSetEquals(t *testing.T) {
169169
if a.Equal(b) {
170170
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
171171
}
172+
if b.Equal(a) {
173+
t.Errorf("Expected to be not-equal: %v vs %v", b, a)
174+
}
172175

173176
b = New[string]("1", "2", "")
174177
if a.Equal(b) {
175178
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
176179
}
180+
if b.Equal(a) {
181+
t.Errorf("Expected to be not-equal: %v vs %v", b, a)
182+
}
177183

178184
// Check for equality after mutation
179185
a = New[string]()

0 commit comments

Comments
 (0)