-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax_test.go
More file actions
118 lines (112 loc) · 1.86 KB
/
Copy pathsyntax_test.go
File metadata and controls
118 lines (112 loc) · 1.86 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package eutil_test
import (
"testing"
"github.com/tcp404/eutil"
)
func TestMap(t *testing.T) {
add := func(x int) int { return x + 1 }
type teststruct[T any] struct {
fn func(T) T
args []T
want []T
}
tests := []teststruct[int]{
{
fn: add,
args: []int{10, 20, 30},
want: []int{11, 21, 31},
},
{
fn: add,
want: []int{},
},
{
fn: add,
args: []int{10},
want: []int{11},
},
}
for _, tc := range tests {
got := eutil.Map(tc.fn, tc.args...)
want := tc.want
for i, v := range got {
if v != want[i] {
t.Errorf("want: %#v, got: %#v", want[i], v)
}
}
}
}
func TestReduce(t *testing.T) {
add := func(x, y int) int { return x + y }
type teststruct[T any] struct {
fn func(T, T) T
args []T
want T
}
tests := []teststruct[int]{
{
fn: add,
args: []int{100, 89, 76, 87},
want: 352,
},
{
fn: add,
want: 0,
},
{
fn: add,
args: []int{10},
want: 10,
},
}
for _, tc := range tests {
got := eutil.Reduce(tc.fn, tc.args...)
want := tc.want
if got != want {
t.Errorf("want: %#v, got: %#v", want, got)
}
}
}
func TestReduce_Zero(t *testing.T) {
add := func(x, y int) int {
return x + y
}
got := eutil.Reduce(add)
want := 0
if got != want {
t.Errorf("want: %#v, got: %#v", want, got)
}
}
func TestFilter(t *testing.T) {
add := func(x int) bool { return x > 40 }
type teststruct[T any] struct {
fn func(T) bool
args []T
want []T
}
tests := []teststruct[int]{
{
fn: add,
args: []int{100, 41, 23, 554, 33},
want: []int{100, 41, 554},
},
{
fn: add,
want: []int{},
},
{
fn: add,
args: []int{10},
want: []int{},
},
}
for _, tc := range tests {
got := eutil.Filter(tc.fn, tc.args...)
want := []any{100, 41, 554}
for i, v := range got {
if v != want[i] {
t.Errorf("want: %#v, got: %#v", want[i], v)
}
}
}
}