-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslices_test.go
54 lines (39 loc) · 1.21 KB
/
slices_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
package mango
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMap(t *testing.T) {
lst := []int{1, 2, 3}
expected := []int{2, 4, 6}
actual := Map(lst, func(i int) int { return i * 2 })
assert.Equal(t, expected, actual)
}
func TestFilter(t *testing.T) {
lst := []int{1, 2, 3}
expected := []int{2}
actual := Filter(lst, func(i int) bool { return i%2 == 0 })
assert.Equal(t, expected, actual)
}
func TestFind(t *testing.T) {
lst := []int{1, 2, 3}
actual, ok := Find(lst, func(i int) bool { return i == 2 })
require.True(t, ok)
require.Equal(t, 2, actual)
actual, ok = Find(lst, func(i int) bool { return i == 45 })
require.False(t, ok)
require.Equal(t, 0, actual)
}
func TestSliceEqual(t *testing.T) {
first := []int{1, 2, 3}
second := []int{1, 2, 3}
assert.True(t, SliceEqual(first, second, func(a, b int) bool { return a == b }))
assert.False(t, SliceEqual(first, []int{1, 2}, func(a, b int) bool { return a == b }))
}
func TestStringSliceEqual(t *testing.T) {
first := []string{"hello", "world"}
second := []string{"hello", "world"}
assert.True(t, StringSliceEqual(first, second))
assert.False(t, StringSliceEqual(first, []string{"hello"}))
}