-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspec_test.go
124 lines (105 loc) · 2.75 KB
/
spec_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
package gostream
import (
"github.com/a3d21/gostream/gopark"
"reflect"
"sort"
"testing"
"testing/quick"
)
func TestSlice2MapSpec(t *testing.T) {
assertion := func(vs []int) bool {
m1 := From(vs).Map(func(it interface{}) interface{} {
return KeyValue{
Key: it,
Value: true,
}
}).Collect(ToMap(map[int]bool{})).(map[int]bool)
m2 := gopark.Slice2Map(vs)
return reflect.DeepEqual(m1, m2)
}
if err := quick.Check(assertion, &quick.Config{MaxCount: 2000}); err != nil {
t.Error(err)
}
}
func TestToSetSpec(t *testing.T) {
assertion := func(vs []int) bool {
m1 := From(vs).Collect(ToSet(map[int]bool{})).(map[int]bool)
m2 := gopark.Slice2Map(vs)
return reflect.DeepEqual(m1, m2)
}
if err := quick.Check(assertion, &quick.Config{MaxCount: 2000}); err != nil {
t.Error(err)
}
}
func TestKeysSpec(t *testing.T) {
assertion := func(m map[string]int64) bool {
s1 := From(m).Map(func(kv interface{}) interface{} {
return kv.(KeyValue).Key
}).SortedBy(identity).Collect(ToSlice([]string{})).([]string)
s2 := gopark.Keys(m)
sort.Strings(s2)
return reflect.DeepEqual(s1, s2) || (len(s1) == 0 && len(s2) == 0)
}
if err := quick.Check(assertion, &quick.Config{MaxCount: 2000}); err != nil {
t.Error(err)
}
}
func TestValuesSpec(t *testing.T) {
assertion := func(m map[string]int) bool {
s1 := From(m).Map(func(kv interface{}) interface{} {
return kv.(KeyValue).Value
}).SortedBy(identity).Collect(ToSlice([]int{})).([]int)
s2 := gopark.Values(m)
sort.Ints(s2)
return reflect.DeepEqual(s1, s2) || (len(s1) == 0 && len(s2) == 0)
}
if err := quick.Check(assertion, &quick.Config{MaxCount: 2000}); err != nil {
t.Error(err)
}
}
/**
func TestMultiSortSpec(t *testing.T) {
type foo struct {
I int
I32 int32
UI64 uint64
F32 float32
S string
B bool
}
assertion := func(vs []foo) bool {
vs = From(vs).Map(func(t interface{}) interface{} {
f := t.(foo)
return foo{
I: f.I % 20,
I32: f.I32 % 20,
UI64: f.UI64 % 20,
F32: f.F32,
S: f.S,
B: f.B,
}
}).Collect(ToSlice([]foo{})).([]foo)
got1 := From(vs).SortedBy(func(t interface{}) interface{} {
f := t.(foo)
return GTuple{f.I, f.I32, f.UI64, f.F32, f.S, f.B}
}).Collect(ToSlice([]foo{})).([]foo)
var got2 []foo
linq.From(vs).OrderByT(func(f foo) interface{} {
return f.I
}).ThenByT(func(f foo) interface{} {
return f.I32
}).ThenByT(func(f foo) interface{} {
return f.UI64
}).ThenByT(func(f foo) interface{} {
return f.F32
}).ThenByT(func(f foo) interface{} {
return f.S
}).ThenByT(func(f foo) interface{} {
return f.B
}).ToSlice(&got2)
return reflect.DeepEqual(got1, got2)
}
if err := quick.Check(assertion, &quick.Config{MaxCount: 5000}); err != nil {
t.Error(err)
}
}*/