File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,18 @@ var (
3636// All is used to iterate through the collection using `for e := range`.
3737func (s * Set [T ]) All (consumer func (T ) bool ) {
3838 if s != nil {
39- slice .WalkWhile (* s .order , consumer )
39+ if order := s .order ; order != nil {
40+ slice .WalkWhile (* order , consumer )
41+ }
4042 }
4143}
4244
4345// IAll is used to iterate through the collection using `for i, e := range`.
4446func (s * Set [T ]) IAll (consumer func (int , T ) bool ) {
4547 if s != nil {
46- slice .TrackWhile (* s .order , consumer )
48+ if order := s .order ; order != nil {
49+ slice .TrackWhile (* order , consumer )
50+ }
4751 }
4852}
4953
Original file line number Diff line number Diff line change @@ -136,6 +136,20 @@ func Test_Set_Nil(t *testing.T) {
136136 assert .False (t , ok )
137137}
138138
139+ func Test_Set_Empty_All (t * testing.T ) {
140+ set := & ordered.Set [int ]{}
141+ assert .Equal (t , 0 , len (seq .Slice (set .All )))
142+ }
143+
144+ func Test_Set_Empty_IAll (t * testing.T ) {
145+ set := & ordered.Set [int ]{}
146+ out := []int {}
147+ for _ , v := range set .IAll {
148+ out = append (out , v )
149+ }
150+ assert .Equal (t , 0 , len (out ))
151+ }
152+
139153func Test_Set_Zero (t * testing.T ) {
140154 var mset ordered.Set [int ]
141155 var nils []int
Original file line number Diff line number Diff line change @@ -26,6 +26,26 @@ func Test_VectorIterate(t *testing.T) {
2626 assert .Equal (t , expected , result )
2727}
2828
29+ func Test_Vector_Empty_IAll (t * testing.T ) {
30+ expected := []int {}
31+ v := & mutable.Vector [int ]{}
32+ result := make ([]int , v .Len ())
33+ for _ , it := range v .IAll {
34+ result = append (result , it )
35+ }
36+ assert .Equal (t , expected , result )
37+ }
38+
39+ func Test_Vector_Empty_All (t * testing.T ) {
40+ expected := []int {}
41+ v := & mutable.Vector [int ]{}
42+ result := make ([]int , v .Len ())
43+ for it := range v .All {
44+ result = append (result , it )
45+ }
46+ assert .Equal (t , expected , result )
47+ }
48+
2949func Test_VectorIterateOverRange (t * testing.T ) {
3050 expected := slice .Of (1 , 2 , 3 , 4 )
3151 v := vector .Of (1 , 2 , 3 , 4 )
You can’t perform that action at this time.
0 commit comments