-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
256 lines (116 loc) · 3.98 KB
/
test.py
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from linq import Flow
def test_Sum():
Flow([(1, 2), (2, 3), (3, 2)]).sum(lambda x, y: x + y)
test_Sum()
def test_Enum():
Flow([(1, 2), (2, 3), (3, 2)]).enum()
test_Enum()
def test_Map():
Flow([(1, 2), (2, 3), (3, 2)]).map(lambda x, y: x + y).to_tuple()
test_Map()
def test_Then():
Flow([(1, 2), (2, 3)]).then(lambda x: x);
Flow([(1, 2), (2, 3)]).then(lambda x, y: x + y)
test_Then()
def test_Scan():
Flow([2, 3, 5]).scan(lambda last, now: last + now, 0).to_list()
test_Scan()
def test_Filter():
Flow([(1, 2), (2, 3), (3, 2)]).filter(lambda x, y: x + y);
Flow([(1, 1), (2, 2), (3, 2)]).Filter(lambda x, y: x is y).Filter().Filter(lambda x: x != (3, 2)).All()
test_Filter()
def test_Each():
Flow([(1, 2), (2, 3), (3, 2)]).each(lambda x, y: x + y)
test_Each()
def test_Aggregate():
Flow([1, 2, 3, 4, 5]).aggregate(max, min, sum)
test_Aggregate()
def test_Zip():
Flow([(1, 2), (2, 3), (3, 2)]).zip([(1, 2), (2, 2), (3, 3)])
test_Zip()
def test_Sorted():
Flow([(1, 2), (2, 3), (3, 2)]).sorted(lambda x, y: x + y)
Flow([1, 2, 3]).sorted().sorted(by=lambda x: -x)
test_Sorted()
def test_ArgSorted():
Flow([(1, 2), (2, 3), (3, 2)]).arg_sorted(lambda x, y: x + y);
Flow([3, 2, 1]).arg_sorted()
Flow([(1, 1), (2, 2), (3, 1)]).arg_sorted(by=lambda a, b: a * b).ToList()
test_ArgSorted()
def test_Group():
Flow([(1, 2), (2, 3), (3, 2)]).Group(lambda x, y: x + y).ToTuple();
Flow([1, 1, 2, 3, 3]).Group().Map(lambda _: (len(_), len(_))).Group(lambda a, b: a * b).ToTuple()
test_Group()
def test_GroupBy():
Flow([(1, 2), (2, 3), (3, 2)]).GroupBy(lambda x, y: x + y).ToTuple();
Flow([1, 1, 1]).GroupBy().ToList()
test_GroupBy()
def test_Take():
Flow([(1, 2), (2, 3), (3, 2)]).Take(1).ToTuple()
test_Take()
def test_TakeIf():
Flow([(1, 2), (2, 3), (3, 2)]).TakeIf(lambda x, y: x + y).ToTuple();
Flow([1, 2, 3]).TakeIf(lambda x: x % 2).ToTuple()
test_TakeIf()
def test_TakeWhile():
Flow([(1, 2), (2, 3), (3, 2)]).TakeWhile(lambda x, y: x + y).ToTuple();
Flow([1, 2, 3, 4, 5, 6]).TakeWhile(lambda x: x < 3).ToTuple()
test_TakeWhile()
def test_Drop():
Flow([(1, 2), (2, 3), (3, 2)]).Drop(1)
test_Drop()
def test_Skip():
Flow([(1, 2), (2, 3), (3, 2)]).Skip(1)
test_Skip()
def test_Concat():
Flow([(1, 2), (2, 3), (3, 2)]).Concat([(1, 2), (2, 2), (3, 3)]).ToTuple()
test_Concat()
def test_ToList():
Flow([(1, 2), (2, 3), (3, 2)]).ToList()
test_ToList()
def test_ToTuple():
Flow([(1, 2), (2, 3), (3, 2)]).ToTuple()
test_ToTuple()
def test_ToDict():
Flow([(1, 1), (2, 2), (3, 3)]).ToDict()
test_ToDict()
def test_ToSet():
Flow([(1, 2), (2, 3), (3, 2)]).ToSet()
test_ToSet()
def test_All():
Flow([(1, 2), (2, 3), (3, 2)]).All(lambda x, y: x + y);
Flow([1, 1, 1]).All()
test_All()
def test_Any():
Flow([(1, 2), (2, 3), (3, 2)]).Any(lambda x, y: x + y);
Flow([1, 1, 1]).Any()
test_Any()
def test_Next():
Flow((i for i in range(3))).first()
test_Next()
def test_Extended():
Flow([(1, 2), (2, 2), (3, 3)]).Extended([(1, 2), (2, 2), (3, 3)])
test_Extended()
def test_Extend():
Flow([(1, 2), (2, 2), (3, 3)]).Extend([(1, 2), (2, 2), (3, 3)])
test_Extend()
def test_Sort():
Flow([(1, 2), (2, 2), (3, 3)]).Sort(lambda x, y: x + y)
test_Sort()
def test_Reverse():
Flow([(1, 2), (2, 2), (3, 3)]).Reverse()
test_Reverse()
def test_Reversed():
Flow([(1, 2), (2, 2), (3, 3)]).Reversed()
test_Reversed()
def test_Intersects():
Flow({(1, 1), (2, 2), (3, 3)}).intersects([(1, 2), (2, 2), (3, 3)])
test_Intersects()
def test_Union():
Flow({(1, 1), (2, 2), (3, 3)}).union([(1, 2), (2, 2), (3, 3)])
test_Union()
def test_Chunk_by():
assert Flow(range(20)).chunk_by(lambda e: e // 4).to_tuple().then(len)._ == 5
assert Flow([1, 1, 2, 2, 3, 3, 3]).chunk_by().map(
lambda group_id, group_members: (group_id, len(group_members))).then(sorted)._ == ([(1, 2), (2, 2), (3, 3)])
test_Chunk_by()