From 4450609677f0d5608107b04320b9be5ee5fca9eb Mon Sep 17 00:00:00 2001 From: Dokiy Date: Tue, 23 Jul 2024 16:48:54 +0800 Subject: [PATCH] fix: method name --- README.md | 4 ++-- intersect.go | 6 +++--- intersect_test.go | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f983ab8c..469913e3 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/intersect.go b/intersect.go index 3df4f684..85609149 100644 --- a/intersect.go +++ b/intersect.go @@ -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 diff --git a/intersect_test.go b/intersect_test.go index e943ff37..f88ab43b 100644 --- a/intersect_test.go +++ b/intersect_test.go @@ -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) }