Skip to content

Commit

Permalink
v2: fix equal and add test for equal
Browse files Browse the repository at this point in the history
  • Loading branch information
zonewave authored and shoenig committed Nov 4, 2023
1 parent ed09455 commit 4cfe145
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func equalSet[T any](a, b Collection[T]) bool {
}
return true
})
return missing
return !missing
}

func removeSet[T any](s, col Collection[T]) bool {
Expand Down
23 changes: 23 additions & 0 deletions collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,26 @@ func TestInsertSetFunc(t *testing.T) {
})
})
}

func TestEqualSet(t *testing.T) {
t.Run("equal ok", func(t *testing.T) {
a := From(ints(3))
b := From(ints(3))
must.True(t, a.EqualSet(b))
})
t.Run("none equal none", func(t *testing.T) {
a := New[int](0)
b := New[int](0)
must.True(t, a.EqualSet(b))
})
t.Run("size not equal", func(t *testing.T) {
a := From(ints(3))
b := From(ints(4))
must.False(t, a.EqualSet(b))
})
t.Run("items not equal", func(t *testing.T) {
a := From(ints(3))
b := From([]int{1, 2, 4})
must.False(t, a.EqualSet(b))
})
}

0 comments on commit 4cfe145

Please sign in to comment.