Skip to content

Commit

Permalink
fix: method name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dokiys committed Jul 23, 2024
1 parent cfaeb62 commit 4450609
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1948,13 +1948,13 @@ b := EveryBy([]int{1, 2, 3, 4}, func(x int) bool {
// true
```

### Equivalent
### EqualUnordered

Returns true if the subset has the same elements and the same number of each element as the collection.
Unlike slices.Equal(), which returns effected by order, Equivalent does not care about the order of the elements.

```go
b := Equivalent([]int{0, 1, 1, 3, 0, 0}, []int{0, 1, 3, 0, 1, 0})
b := EqualUnordered([]int{0, 1, 1, 3, 0, 0}, []int{0, 1, 3, 0, 1, 0})
// true
```

Expand Down
6 changes: 3 additions & 3 deletions intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func EveryBy[T any](collection []T, predicate func(item T) bool) bool {
return true
}

// Equivalent Returns true if the subset has the same elements and the same number of each element as the collection.
// Unlike slices.Equal(), which returns effected by order, Equivalent does not care about the order of the elements.
func Equivalent[T comparable, Slice ~[]T](collection, subset Slice) bool {
// EqualUnordered returns true if the subset has the same elements and the same number of each element as the collection.
// Unlike slices.Equal(), which returns effected by order, EqualUnordered does not care about the order of the elements.
func EqualUnordered[T comparable, Slice ~[]T](collection, subset Slice) bool {
l := len(collection)
if l != len(subset) {
return false
Expand Down
14 changes: 7 additions & 7 deletions intersect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ func TestEveryBy(t *testing.T) {
is.True(result4)
}

func TestEquivalent(t *testing.T) {
func TestEqualUnordered(t *testing.T) {
t.Parallel()
is := assert.New(t)

result1 := Equivalent([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 2, 3, 4, 5})
result1 := EqualUnordered([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 2, 3, 4, 5})
is.True(result1)

result2 := Equivalent([]int{2, 3, 4, 5, 0, 1}, []int{0, 1, 2, 3, 4, 5})
result2 := EqualUnordered([]int{2, 3, 4, 5, 0, 1}, []int{0, 1, 2, 3, 4, 5})
is.True(result2)

result3 := Equivalent([]int{0, 1, 1, 3, 0, 0}, []int{0, 1, 3, 0, 1, 0})
result3 := EqualUnordered([]int{0, 1, 1, 3, 0, 0}, []int{0, 1, 3, 0, 1, 0})
is.True(result3)

result4 := Equivalent([]int{0, 1, 2, 3, 4}, []int{0, 1, 2, 3, 4, 5})
result4 := EqualUnordered([]int{0, 1, 2, 3, 4}, []int{0, 1, 2, 3, 4, 5})
is.False(result4)

result5 := Equivalent([]int{0, 1, 2, 3, 4, 6}, []int{0, 1, 2, 3, 4, 5})
result5 := EqualUnordered([]int{0, 1, 2, 3, 4, 6}, []int{0, 1, 2, 3, 4, 5})
is.False(result5)

result6 := Equivalent([]int{0, 1, 1, 1, 1, 1}, []int{0, 0, 1, 1, 1, 1})
result6 := EqualUnordered([]int{0, 1, 1, 1, 1, 1}, []int{0, 0, 1, 1, 1, 1})
is.False(result6)
}

Expand Down

0 comments on commit 4450609

Please sign in to comment.