-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreduce_right_test.go
71 lines (68 loc) · 1.4 KB
/
reduce_right_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package slices
import (
"reflect"
"strconv"
"testing"
)
func TestReduceRight(t *testing.T) {
type args struct {
slice []int
reduce func(total int, item int, index int, slice []int) int
init int
}
tests := []struct {
name string
args args
want int
}{
{
name: "number1",
args: args{
slice: []int{3, 4, 5, 3},
reduce: func(total int, item int, index int, slice []int) int {
return total + item
},
init: 0,
},
want: 15,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ReduceRight(tt.args.slice, tt.args.reduce, tt.args.init); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReduceRight() = %v, want %v", got, tt.want)
}
})
}
}
func TestReduceRight2(t *testing.T) {
type args struct {
slice []int
reduce func(total string, item int, index int, slice []int) string
init string
}
tests := []struct {
name string
args args
want string
}{
{
name: "number1",
args: args{
slice: []int{1, 2, 3, 4, 5},
reduce: func(total string, item int, index int, slice []int) string {
return total + strconv.Itoa(item)
},
init: "",
},
want: "54321",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ReduceRight(tt.args.slice, tt.args.reduce, tt.args.init); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReduceRight() = %v, want %v", got, tt.want)
}
})
}
}