-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathmap_test.go
63 lines (48 loc) · 1.13 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
package un
import (
"runtime"
"strconv"
"strings"
"testing"
)
func TestMapWithSliceInterface(t *testing.T) {
fn := func(s interface{}) interface{} {
return s.(string) + "!"
}
receive := Map(fn, SLICE_STRING)
expect := "a!"
equals(t, expect, receive[0])
}
func TestMapString(t *testing.T) {
fn := func(s string) string {
return s + "!"
}
receive := MapString(fn, SLICE_STRING)
expect := "a!"
equals(t, expect, receive[0])
}
func TestMapInt(t *testing.T) {
fn := func(i int) int {
return i + 1
}
receive := MapInt(fn, SLICE_INT)
expect := 1
equals(t, expect, receive[0])
}
func TestMakePMapWithSlice(t *testing.T) {
runtime.GOMAXPROCS(runtime.NumCPU())
fn := func(s string) string {
return s + "!"
}
receive := MapPString(fn, SLICE_STRING)
assert(t, strings.Contains(receive[0], "!"), "should contain !")
}
func TestMakePMapWithMap(t *testing.T) {
runtime.GOMAXPROCS(runtime.NumCPU())
fn := func(v, k interface{}) interface{} {
return k.(string) + strconv.Itoa(v.(int)) + "!"
}
receive := MapP(fn, MAP_STRING_TO_INT, 20)
display(receive)
// assert(t, strings.Contains(receive[0], "!"), "should contain !")
}