Skip to content

Commit

Permalink
add aggr functions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsldymq committed Apr 4, 2024
1 parent a1faf85 commit 3aaf564
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions funcs_aggregation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package handy

import (
"slices"
"testing"
)

func TestReduce(t *testing.T) {
list := NewList(1, 2, 3, 4, 5)
actual := Reduce(list, 0, func(acc, each int) int {
return acc + each
})
expect := 15
if actual != expect {
t.Fatalf("test Reduce, expect: %v, actual: %v", expect, actual)
}
}

func TestScan(t *testing.T) {
list := NewList(1, 2, 3, 4, 5)
e := Scan(list, 0, func(acc, each int) int {
return acc + each
})
actual := []int{}
for v := range e.Iter() {
actual = append(actual, v)
}
expect := []int{1, 3, 6, 10, 15}
if !slices.Equal(actual, expect) {
t.Fatalf("test Scan, expect: %v, actual: %v", expect, actual)
}
}

0 comments on commit 3aaf564

Please sign in to comment.