-
Notifications
You must be signed in to change notification settings - Fork 1
/
map_test.go
125 lines (111 loc) · 2.22 KB
/
map_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
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
119
120
121
122
123
124
125
package goulash
import (
"math"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMapInt(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input []int
expect []float64
}{
{
name: "Empty slice",
input: []int{},
expect: []float64{},
},
{
name: "Pow10 all elements",
input: []int{1, 2, 3},
expect: []float64{10, 100, 1000},
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, testCase.expect, Map(testCase.input, math.Pow10))
})
}
}
func TestMapFloat32(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input []float32
expect []uint32
}{
{
name: "Empty slice",
input: []float32{},
expect: []uint32{},
},
{
name: "Log all elements",
input: []float32{1, 2, 3},
expect: []uint32{1065353216, 1073741824, 1077936128},
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, testCase.expect, Map(testCase.input, math.Float32bits))
})
}
}
func TestMapFloat64(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input []float64
expect []float64
}{
{
name: "Empty slice",
input: []float64{},
expect: []float64{},
},
{
name: "Log all elements",
input: []float64{1, 2, 3},
expect: []float64{0, 0.6931471805599453, 1.0986122886681096},
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, testCase.expect, Map(testCase.input, math.Log))
})
}
}
func TestMapString(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
input []string
expect [][]string
}{
{
name: "Empty slice",
input: []string{},
expect: [][]string{},
},
{
name: "Run Fields on all elements",
input: []string{"a", "b", "c"},
expect: [][]string{{"a"}, {"b"}, {"c"}},
},
}
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, testCase.expect, Map(testCase.input, strings.Fields))
})
}
}