From e2522cd29b12f0acece7c88ec51aee1ce687adac Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 29 Mar 2023 10:24:41 +0800 Subject: [PATCH] fix: fix TestEachWithBreak case --- datastructure/set/set.go | 2 +- datastructure/set/set_test.go | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/datastructure/set/set.go b/datastructure/set/set.go index 73da900..60326dd 100644 --- a/datastructure/set/set.go +++ b/datastructure/set/set.go @@ -175,7 +175,7 @@ func (s Set[T]) Minus(comparedSet Set[T]) Set[T] { // EachWithBreak iterates over elements of a set and invokes function for each element, // when iteratee return false, will break the for each loop. func (s Set[T]) EachWithBreak(iteratee func(item T) bool) { - for v := range s { + for _, v := range s.Values() { if !iteratee(v) { break } diff --git a/datastructure/set/set_test.go b/datastructure/set/set_test.go index 66c590c..62595bc 100644 --- a/datastructure/set/set_test.go +++ b/datastructure/set/set_test.go @@ -194,20 +194,20 @@ func TestSet_Minus(t *testing.T) { } func TestEachWithBreak(t *testing.T) { - // s := NewSet(1, 2, 3, 4, 5) + s := NewSet(1, 2, 3, 4, 5) - // var sum int + var sum int - // s.EachWithBreak(func(n int) bool { - // if n > 3 { - // return false - // } - // sum += n - // return true - // }) + s.EachWithBreak(func(n int) bool { + if n > 3 { + return false + } + sum += n + return true + }) - // assert := internal.NewAssert(t, "TestEachWithBreak") - // assert.Equal(6, sum) + assert := internal.NewAssert(t, "TestEachWithBreak") + assert.Equal(6, sum) } // func TestPop(t *testing.T) {