Skip to content

Commit 717d538

Browse files
authored
#22, #29 - major refactor (#30)
* #22, #29 - major refactor - Removed all methods that can be easily implemented by using iterator of `Values()` and methods alike - Separated argument function for indexed and non-indexed collections * #22, #29 - CR - added comment reducing confusion * #22, #29 - CR - some capacity optimizations in internal functions
1 parent d058770 commit 717d538

18 files changed

+165
-4277
lines changed

base_cases_test.go

Lines changed: 3 additions & 781 deletions
Large diffs are not rendered by default.

cmp_cases_test.go

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coll
22

33
import (
4-
"errors"
54
"testing"
65
)
76

@@ -306,129 +305,3 @@ func testLastIndexOf[C cmpInternal[int]](t *testing.T, builder testCollectionBui
306305
})
307306
}
308307
}
309-
310-
func getMaxCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] {
311-
return []testCase[C, int]{
312-
{
313-
name: "Max() on empty collection",
314-
coll: builder.Empty(),
315-
want1: 0,
316-
err: ErrEmptyCollection,
317-
},
318-
{
319-
name: "Max() on one-item collection",
320-
coll: builder.One(),
321-
want1: 111,
322-
},
323-
{
324-
name: "Max() on three-item collection",
325-
coll: builder.Three(),
326-
want1: 333,
327-
},
328-
{
329-
name: "Max() on six-item collection",
330-
coll: builder.SixWithDuplicates(),
331-
want1: 333,
332-
},
333-
}
334-
}
335-
336-
func testMax[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) {
337-
cases := getMaxCases(builder)
338-
for _, tt := range cases {
339-
t.Run(tt.name, func(t *testing.T) {
340-
got, err := tt.coll.Max()
341-
if err != nil {
342-
if !errors.Is(err, tt.err) {
343-
t.Errorf("Max() error = %v, wantErr %v", err, tt.err)
344-
}
345-
} else if got != tt.want1 {
346-
t.Errorf("Max() = %v, want1 %v", got, tt.want1)
347-
}
348-
})
349-
}
350-
}
351-
352-
func getMinCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] {
353-
return []testCase[C, int]{
354-
{
355-
name: "Min() on empty collection",
356-
coll: builder.Empty(),
357-
want1: 0,
358-
err: ErrEmptyCollection,
359-
},
360-
{
361-
name: "Min() on one-item collection",
362-
coll: builder.One(),
363-
want1: 111,
364-
},
365-
{
366-
name: "Min() on three-item collection",
367-
coll: builder.Three(),
368-
want1: 111,
369-
},
370-
{
371-
name: "Min() on three-item collection reversed",
372-
coll: builder.ThreeRev(),
373-
want1: 111,
374-
},
375-
{
376-
name: "Min() on six-item collection",
377-
coll: builder.SixWithDuplicates(),
378-
want1: 111,
379-
},
380-
}
381-
}
382-
383-
func testMin[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) {
384-
cases := getMinCases(builder)
385-
for _, tt := range cases {
386-
t.Run(tt.name, func(t *testing.T) {
387-
got, err := tt.coll.Min()
388-
if err != nil {
389-
if !errors.Is(err, tt.err) {
390-
t.Errorf("Min() error = %v, wantErr %v", err, tt.err)
391-
}
392-
} else if got != tt.want1 {
393-
t.Errorf("Min() = %v, want1 %v", got, tt.want1)
394-
}
395-
})
396-
}
397-
}
398-
399-
func getSumCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] {
400-
return []testCase[C, int]{
401-
{
402-
name: "Sum() on empty collection",
403-
coll: builder.Empty(),
404-
want1: 0,
405-
},
406-
{
407-
name: "Sum() on one-item collection",
408-
coll: builder.One(),
409-
want1: 111,
410-
},
411-
{
412-
name: "Sum() on three-item collection",
413-
coll: builder.Three(),
414-
want1: 666,
415-
},
416-
{
417-
name: "Sum() on six-item collection",
418-
coll: builder.SixWithDuplicates(),
419-
want1: 1332,
420-
},
421-
}
422-
}
423-
424-
func testSum[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) {
425-
cases := getSumCases(builder)
426-
for _, tt := range cases {
427-
t.Run(tt.name, func(t *testing.T) {
428-
got := tt.coll.Sum()
429-
if got != tt.want1 {
430-
t.Errorf("Sum() = %v, want1 %v", got, tt.want1)
431-
}
432-
})
433-
}
434-
}

common_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ type testArgs[C any, V any] struct {
88
values []V
99
defaultValue V
1010
defaultRawValue any
11-
visit Visitor[V]
12-
predicate Predicate[V]
11+
visit func(v V)
12+
predicate func(v V) bool
1313
intPredicate func(i int) bool
14-
reducer Reducer[V]
15-
mapper Mapper[V]
14+
mapper func(val V) V
1615
comparer func(a, b V) int
1716
initial V
1817
coll C

0 commit comments

Comments
 (0)