-
Notifications
You must be signed in to change notification settings - Fork 50
/
tests.py
821 lines (499 loc) · 26.6 KB
/
tests.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
from dsl import *
A = ((1, 0), (0, 1), (1, 0))
B = ((2, 1), (0, 1), (2, 1))
C = ((3, 4), (5, 5))
D = ((1, 2, 3), (4, 5, 6), (7, 8, 0))
E = ((1, 2), (4, 5))
F = ((5, 6), (8, 0))
G = ((1, 0, 0, 0, 3), (0, 1, 1, 0, 0), (0, 1, 1, 2, 0), (0, 0, 2, 2, 0), (0, 2, 0, 0, 0))
H = ((0, 0, 0, 0, 0), (0, 2, 0, 2, 0), (2, 0, 0, 2, 0), (0, 0, 0, 0, 0), (0, 0, 2, 0, 0))
I = ((0, 0, 2, 0, 0), (0, 2, 0, 2, 0), (2, 0, 0, 2, 0), (0, 2, 0, 2, 0), (0, 0, 2, 0, 0))
J = ((0, 0, 2, 0, 0), (0, 2, 0, 2, 0), (0, 0, 2, 2, 0), (0, 2, 0, 2, 0), (0, 0, 2, 0, 0))
K = ((0, 0, 1, 0, 0, 1, 0, 0), (0, 0, 1, 0, 0, 1, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1), (0, 0, 1, 0, 0, 1, 0, 0), (0, 0, 1, 0, 0, 1, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1), (0, 0, 1, 0, 0, 1, 0, 0), (0, 0, 1, 0, 0, 1, 0, 0))
def test_identity():
assert identity(1) == 1
def test_add():
assert add(1, 2) == 3
assert add(4, 6) == 10
def test_subtract():
assert subtract(1, 2) == -1
assert subtract(4, 6) == -2
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(4, 3) == 12
def test_divide():
assert divide(4, 2) == 2
assert divide(9, 2) == 4
def test_invert():
assert invert(1) == -1
assert invert(-4) == 4
def test_even():
assert not even(1)
assert even(2)
def test_double():
assert double(1) == 2
def test_halve():
assert halve(2) == 1
assert halve(5) == 2
def test_flip():
assert flip(False)
assert not flip(True)
def test_equality():
assert equality(A, A)
assert not equality(A, B)
def test_contained():
assert contained(1, (1, 3))
assert not contained(2, {3, 4})
def test_combine():
assert combine(frozenset({1, 2}), frozenset({3, 4})) == frozenset({1, 2, 3, 4})
assert combine((1, 2), (3, 4)) == (1, 2, 3, 4)
def test_intersection():
assert intersection(frozenset({1, 2}), frozenset({2, 3})) == frozenset({2})
def test_difference():
assert difference(frozenset({1, 2, 3}), frozenset({1, 2})) == frozenset({3})
def test_dedupe():
assert dedupe((1, 2, 3, 3, 2, 4, 1)) == (1, 2, 3, 4)
def test_order():
assert order(((1,), (1, 2, 3), (1, 2)), len) == ((1,), (1, 2), (1, 2, 3))
assert order((1, 4, -3), abs) == (1, -3, 4)
def test_repeat():
assert repeat(C, 3) == (C, C, C)
def test_greater():
assert greater(2, 1)
assert not greater(4, 10)
def test_size():
assert size((1, 2, 3)) == 3
assert size(frozenset({2, 5})) == 2
def test_merge():
assert merge(frozenset({frozenset({(1, (0, 0))}), frozenset({(1, (1, 1)), (1, (0, 1))})})) == frozenset({(1, (0, 0)), (1, (1, 1)), (1, (0, 1))})
assert merge(((1, 2), (3, 4, 5))) == (1, 2, 3, 4, 5)
assert merge(((4, 5), (7,))) == (4, 5, 7)
def test_maximum():
assert maximum({1, 2, 5, 3}) == 5
assert maximum((4, 2, 6)) == 6
def test_minimum():
assert minimum({1, 2, 5, 3}) == 1
assert minimum((4, 2, 6)) == 2
def test_valmax():
assert valmax(((1,), (1, 2)), len) == 2
def test_valmin():
assert valmin(((1,), (1, 2)), len) == 1
def test_argmax():
assert argmax(((1,), (1, 2)), len) == (1, 2)
def test_argmin():
assert argmin(((1,), (1, 2)), len) == (1,)
def test_mostcommon():
assert mostcommon((1, 2, 2, 3, 3, 3)) == 3
def test_leastcommon():
assert leastcommon((1, 2, 3, 4, 2, 3, 4)) == 1
def test_initset():
assert initset(2) == frozenset({2})
def test_both():
assert not both(True, False)
assert both(True, True)
assert not both(False, False)
def test_either():
assert either(True, False)
assert either(True, True)
assert not either(False, False)
def test_increment():
assert increment(1) == 2
def test_decrement():
assert decrement(1) == 0
def test_crement():
assert crement(1) == 2
assert crement(-2) == -3
def test_sign():
assert sign(2) == 1
assert sign(0) == 0
assert sign(-1) == -1
def test_positive():
assert positive(1)
assert not positive(-2)
def test_toivec():
assert toivec(2) == (2, 0)
def test_tojvec():
assert tojvec(3) == (0, 3)
def test_sfilter():
assert sfilter((1, 2, 3), lambda x: x > 1) == (2, 3)
assert sfilter(frozenset({2, 3, 4}), lambda x: x % 2 == 0) == frozenset({2, 4})
def test_mfilter():
assert mfilter(frozenset({frozenset({(2, (3, 3))}), frozenset({(1, (0, 0))}), frozenset({(1, (1, 1)), (1, (0, 1))})}), lambda x: len(x) == 1) == frozenset({(1, (0, 0)), (2, (3, 3))})
def test_extract():
assert extract((1, 2, 3), lambda x: x > 2) == 3
assert extract(frozenset({2, 3, 4}), lambda x: x % 4 == 0) == 4
def test_totuple():
assert totuple({1}) == (1,)
def test_first():
assert first((2, 3)) == 2
def test_last():
assert last((2, 3)) == 3
def test_insert():
assert insert(1, frozenset({2})) == frozenset({1, 2})
def test_remove():
assert remove(1, frozenset({1, 2})) == frozenset({2})
def test_other():
assert other({1, 2}, 1) == 2
def test_interval():
assert interval(1, 4, 1) == (1, 2, 3)
assert interval(5, 2, -1) == (5, 4, 3)
def test_astuple():
assert astuple(3, 4) == (3, 4)
def test_product():
assert product({1, 2}, {2, 3}) == frozenset({(1, 2), (1, 3), (2, 2), (2, 3)})
def test_pair():
assert pair((1, 2), (4, 3)) == ((1, 4), (2, 3))
def test_branch():
assert branch(True, 1, 3) == 1
assert branch(False, 4, 2) == 2
def test_compose():
assert compose(lambda x: x ** 2, lambda x: x + 1)(2) == 9
assert compose(lambda x: x + 1, lambda x: x ** 2)(2) == 5
def test_chain():
assert chain(lambda x: x + 3, lambda x: x ** 2, lambda x: x + 1)(2) == 12
def test_matcher():
assert matcher(lambda x: x + 1, 3)(2)
assert not matcher(lambda x: x - 1, 3)(2)
def test_rbind():
assert rbind(lambda a, b: a + b, 2)(3) == 5
assert rbind(lambda a, b: a == b, 2)(2)
def test_lbind():
assert lbind(lambda a, b: a + b, 2)(3) == 5
assert lbind(lambda a, b: a == b, 2)(2)
def test_power():
assert power(lambda x: x + 1, 3)(4) == 7
def test_fork():
assert fork(lambda x, y: x * y, lambda x: x + 1, lambda x: x + 2)(2) == 12
def test_apply():
assert apply(lambda x: x ** 2, (1, 2, 3)) == (1, 4, 9)
assert apply(lambda x: x % 2, frozenset({1, 2})) == frozenset({0, 1})
def test_rapply():
assert rapply(frozenset({lambda x: x + 1, lambda x: x - 1}), 1) == {0, 2}
def test_mapply():
assert mapply(lambda x: frozenset({(v + 1, (i, j)) for v, (i, j) in x}), frozenset({frozenset({(1, (0, 0))}), frozenset({(1, (1, 1)), (1, (0, 1))})})) == frozenset({(2, (0, 0)), (2, (1, 1)), (2, (0, 1))})
def test_papply():
assert papply(lambda x, y: x + y, (1, 2), (3, 4)) == (4, 6)
def test_mpapply():
assert mpapply(lambda x, y: frozenset({(x, (i, j)) for _, (i, j) in y}), (3, 4), frozenset({frozenset({(1, (0, 0))}), frozenset({(1, (1, 1)), (1, (0, 1))})})) == ((3, (0, 0)), (4, (1, 1)), (4, (0, 1)))
def test_prapply():
assert prapply(lambda x, y: x + y, {1, 2}, {2, 3}) == frozenset({3, 4, 5})
def test_mostcolor():
assert mostcolor(B) == 1
assert mostcolor(C) == 5
def test_leastcolor():
assert leastcolor(B) == 0
def test_height():
assert height(A) == 3
assert height(C) == 2
assert height(frozenset({(0, 4)})) == 1
assert height(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 3
def test_width():
assert width(A) == 2
assert width(C) == 2
assert width(frozenset({(0, 4)})) == 1
assert width(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 3
def test_shape():
assert shape(A) == (3, 2)
assert shape(C) == (2, 2)
assert shape(frozenset({(0, 4)})) == (1, 1)
assert shape(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == (3, 3)
def test_portrait():
assert portrait(A)
assert not portrait(C)
def test_colorcount():
assert colorcount(A, 1) == 3
assert colorcount(C, 5) == 2
assert colorcount(frozenset({(1, (0, 0)), (2, (1, 0)), (2, (0, 1))}), 2) == 2
assert colorcount(frozenset({(1, (0, 0)), (2, (1, 0)), (2, (0, 1))}), 1) == 1
def test_colorfilter():
assert colorfilter(frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))}), frozenset({(1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (3, 2)), (2, (2, 3)), (2, (3, 3))})}), 2) == frozenset({frozenset({(2, (4, 1))}), frozenset({(2, (3, 2)), (2, (2, 3)), (2, (3, 3))})})
def test_sizefilter():
assert sizefilter(frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))}), frozenset({(1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (3, 2)), (2, (2, 3)), (2, (3, 3))})}), 1) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))})})
def test_asindices():
assert asindices(A) == frozenset({(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)})
assert asindices(C) == frozenset({(0, 0), (0, 1), (1, 0), (1, 1)})
def test_ofcolor():
assert ofcolor(A, 0) == frozenset({(0, 1), (1, 0), (2, 1)})
assert ofcolor(B, 2) == frozenset({(0, 0), (2, 0)})
assert ofcolor(C, 1) == frozenset()
def test_ulcorner():
assert ulcorner(frozenset({(1, 2), (0, 3), (4, 0)})) == (0, 0)
assert ulcorner(frozenset({(1, 2), (0, 0), (4, 3)})) == (0, 0)
def test_urcorner():
assert urcorner(frozenset({(1, 2), (0, 3), (4, 0)})) == (0, 3)
assert urcorner(frozenset({(1, 2), (0, 0), (4, 3)})) == (0, 3)
def test_llcorner():
assert llcorner(frozenset({(1, 2), (0, 3), (4, 0)})) == (4, 0)
assert llcorner(frozenset({(1, 5), (0, 0), (2, 3)})) == (2, 0)
def test_lrcorner():
assert lrcorner(frozenset({(1, 2), (0, 3), (4, 0)})) == (4, 3)
assert lrcorner(frozenset({(1, 5), (0, 0), (2, 3)})) == (2, 5)
def test_crop():
assert crop(A, (0, 0), (2, 2)) == ((1, 0), (0, 1))
assert crop(C, (0, 1), (1, 1)) == ((4,),)
assert crop(D, (1, 2), (2, 1)) == ((6,), (0,))
def test_toindices():
assert toindices(frozenset({(1, (1, 1)), (1, (1, 0))})) == frozenset({(1, 1), (1, 0)})
assert toindices(frozenset({(1, 1), (0, 1)})) == frozenset({(1, 1), (0, 1)})
def test_recolor():
assert recolor(3, frozenset({(2, (0, 0)), (1, (0, 1)), (5, (1, 0))})) == frozenset({(3, (0, 0)), (3, (0, 1)), (3, (1, 0))})
assert recolor(2, frozenset({(2, (2, 5)), (2, (1, 1))})) == frozenset({(2, (2, 5)), (2, (1, 1))})
def test_shift():
assert shift(frozenset({(2, (1, 1)), (4, (1, 2)), (1, (2, 3))}), (1, 2)) == frozenset({(2, (2, 3)), (4, (2, 4)), (1, (3, 5))})
assert shift(frozenset({(1, 3), (0, 2), (3, 4)}), (0, -1)) == frozenset({(1, 2), (0, 1), (3, 3)})
def test_normalize():
assert normalize(frozenset({(2, (1, 1)), (4, (1, 2)), (1, (2, 3))})) == frozenset({(2, (0, 0)), (4, (0, 1)), (1, (1, 2))})
assert normalize(frozenset({(1, 0), (0, 2), (3, 4)})) == frozenset({(1, 0), (0, 2), (3, 4)})
def test_dneighbors():
assert dneighbors((1, 1)) == frozenset({(0, 1), (1, 0), (2, 1), (1, 2)})
assert dneighbors((0, 0)) == frozenset({(0, 1), (1, 0), (-1, 0), (0, -1)})
assert dneighbors((0, 1)) == frozenset({(0, 0), (1, 1), (-1, 1), (0, 2)})
assert dneighbors((1, 0)) == frozenset({(0, 0), (1, 1), (1, -1), (2, 0)})
def test_ineighbors():
assert ineighbors((1, 1)) == frozenset({(0, 0), (0, 2), (2, 0), (2, 2)})
assert ineighbors((0, 0)) == frozenset({(1, 1), (-1, -1), (1, -1), (-1, 1)})
assert ineighbors((0, 1)) == frozenset({(1, 0), (1, 2), (-1, 0), (-1, 2)})
assert ineighbors((1, 0)) == frozenset({(0, 1), (2, -1), (2, 1), (0, -1)})
def test_neighbors():
assert neighbors((1, 1)) == frozenset({(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)})
assert neighbors((0, 0)) == frozenset({(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)})
def test_objects():
assert objects(G, True, False, True) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))}), frozenset({(1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (3, 2)), (2, (2, 3)), (2, (3, 3))})})
assert objects(G, True, True, True) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (4, 1)), (2, (3, 2)), (2, (2, 3)), (2, (3, 3))})})
assert objects(G, False, False, True) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))}), frozenset({(1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2)), (2, (3, 2)), (2, (2, 3)), (2, (3, 3))})})
assert objects(G, False, True, True) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2)), (2, (4, 1)), (2, (3, 2)), (2, (2, 3)), (2, (3, 3))})})
assert objects(G, True, False, False) == frozenset({frozenset({(3, (0, 4))}), frozenset({(1, (0, 0))}), frozenset({(2, (4, 1))}), frozenset({(1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (3, 2)), (2, (2, 3)), (2, (3, 3))}), frozenset({(0, (1, 0)), (0, (2, 0)), (0, (3, 0)), (0, (4, 0)), (0, (3, 1))}), frozenset({(0, (0, 1)), (0, (0, 2)), (0, (0, 3)), (0, (1, 3)), (0, (1, 4)), (0, (2, 4)), (0, (3, 4)), (0, (4, 4)), (0, (4, 3)), (0, (4, 2))})})
def test_partition():
assert partition(B) == frozenset({frozenset({(0, (1, 0))}), frozenset({(2, (0, 0)), (2, (2, 0))}), frozenset({(1, (0, 1)), (1, (1, 1)), (1, (2, 1))})})
assert partition(G) == frozenset({frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (4, 1)), (2, (3, 2)), (2, (2, 3)), (2, (3, 3))}), frozenset({(3, (0, 4))}), frozenset({(0, (0, 1)), (0, (0, 2)), (0, (0, 3)), (0, (1, 0)), (0, (1, 3)), (0, (1, 4)), (0, (2, 0)), (0, (2, 4)), (0, (3, 0)), (0, (3, 1)), (0, (3, 4)), (0, (4, 0)), (0, (4, 2)), (0, (4, 3)), (0, (4, 4))})})
def test_fgpartition():
assert fgpartition(B) == frozenset({frozenset({(0, (1, 0))}), frozenset({(2, (0, 0)), (2, (2, 0))})})
assert fgpartition(G) == frozenset({frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))}), frozenset({(2, (4, 1)), (2, (3, 2)), (2, (2, 3)), (2, (3, 3))}), frozenset({(3, (0, 4))})})
def test_uppermost():
assert uppermost(frozenset({(0, 4)})) == 0
assert uppermost(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 0
def test_lowermost():
assert lowermost(frozenset({(0, 4)})) == 0
assert lowermost(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 2
def test_leftmost():
assert leftmost(frozenset({(0, 4)})) == 4
assert leftmost(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 0
def test_rightmost():
assert rightmost(frozenset({(0, 4)})) == 4
assert rightmost(frozenset({(1, (0, 0)), (1, (1, 1)), (1, (1, 2)), (1, (2, 1)), (1, (2, 2))})) == 2
def test_square():
assert square(C)
assert square(D)
assert not square(A)
assert not square(B)
assert not square(frozenset({(1, 1), (1, 0)}))
assert square(frozenset({(1, 1), (0, 0), (1, 0), (0, 1)}))
assert not square(frozenset({(0, 0), (1, 0), (0, 1)}))
assert square(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))}))
def test_vline():
assert vline(frozenset({(1, (1, 1)), (1, (0, 1))}))
assert not vline(frozenset({(1, 1), (1, 0)}))
def test_hline():
assert hline(frozenset({(1, (1, 1)), (1, (1, 0))}))
assert not hline(frozenset({(1, 1), (0, 1)}))
def test_hmatching():
assert hmatching(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))}), frozenset({(1, (1, 3)), (2, (1, 4))}))
assert not hmatching(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))}), frozenset({(1, (2, 3)), (2, (2, 4))}))
def test_vmatching():
assert vmatching(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))}), frozenset({(1, (3, 1)), (2, (4, 1))}))
assert not vmatching(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))}), frozenset({(1, (3, 2)), (2, (4, 2))}))
def test_manhattan():
assert manhattan(frozenset({(0, 0), (1, 1)}), frozenset({(1, 2), (2, 3)})) == 1
assert manhattan(frozenset({(1, 1)}), frozenset({(2, 3)})) == 3
def test_adjacent():
assert adjacent(frozenset({(0, 0)}), frozenset({(0, 1), (1, 0)}))
assert not adjacent(frozenset({(0, 0)}), frozenset({(1, 1)}))
def test_bordering():
assert bordering(frozenset({(0, 0)}), D)
assert bordering(frozenset({(0, 2)}), D)
assert bordering(frozenset({(2, 0)}), D)
assert bordering(frozenset({(2, 2)}), D)
assert not bordering(frozenset({(1, 1)}), D)
def test_centerofmass():
assert centerofmass(frozenset({(0, 0), (1, 1), (1, 2)})) == (0, 1)
assert centerofmass(frozenset({(0, 0), (1, 1), (2, 2)})) == (1, 1)
assert centerofmass(frozenset({(0, 0), (1, 1), (0, 1)})) == (0, 0)
def test_palette():
assert palette(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))})) == frozenset({1, 2, 3})
assert palette(frozenset({(1, (1, 1)), (1, (0, 0)), (1, (1, 0)), (1, (0, 1))})) == frozenset({1})
def test_numcolors():
assert numcolors(frozenset({(1, (1, 1)), (2, (0, 0)), (2, (1, 0)), (3, (0, 1))})) == 3
assert numcolors(frozenset({(1, (1, 1)), (1, (0, 0)), (1, (1, 0)), (1, (0, 1))})) == 1
def test_color():
assert color(frozenset({(1, (1, 1)), (1, (0, 0)), (1, (1, 0)), (1, (0, 1))})) == 1
assert color(frozenset({(2, (3, 1))})) == 2
def test_toobject():
assert toobject(frozenset({(0, 0), (0, 2)}), G) == frozenset({(1, (0, 0)), (0, (0, 2))})
assert toobject(frozenset({(0, 4)}), G) == frozenset({(3, (0, 4))})
def test_asobject():
assert asobject(A) == frozenset({(0, (0, 1)), (0, (1, 0)), (0, (2, 1)), (1, (0, 0)), (1, (1, 1)), (1, (2, 0))})
def test_rot90():
assert rot90(B) == ((2, 0, 2), (1, 1, 1))
assert rot90(C) == ((5, 3), (5, 4))
def test_rot180():
assert rot180(B) == ((1, 2), (1, 0), (1, 2))
assert rot180(C) == ((5, 5), (4, 3))
def test_rot270():
assert rot270(B) == ((1, 1, 1), (2, 0, 2))
assert rot270(C) == ((4, 5), (3, 5))
def test_hmirror():
assert hmirror(B) == ((2, 1), (0, 1), (2, 1))
assert hmirror(C) == ((5, 5), (3, 4))
assert hmirror(frozenset({(0, 0), (1, 1)})) == frozenset({(1, 0), (0, 1)})
assert hmirror(frozenset({(0, 0), (1, 0), (1, 1)})) == frozenset({(1, 0), (0, 1), (0, 0)})
assert hmirror(frozenset({(0, 1), (1, 2)})) == frozenset({(0, 2), (1, 1)})
def test_vmirror():
assert vmirror(B) == ((1, 2), (1, 0), (1, 2))
assert vmirror(C) == ((4, 3), (5, 5))
assert vmirror(frozenset({(0, 0), (1, 1)})) == frozenset({(1, 0), (0, 1)})
assert vmirror(frozenset({(0, 0), (1, 0), (1, 1)})) == frozenset({(1, 0), (1, 1), (0, 1)})
assert vmirror(frozenset({(0, 1), (1, 2)})) == frozenset({(0, 2), (1, 1)})
def test_dmirror():
assert dmirror(B) == ((2, 0, 2), (1, 1, 1))
assert dmirror(C) == ((3, 5), (4, 5))
assert dmirror(frozenset({(0, 0), (1, 1)})) == frozenset({(0, 0), (1, 1)})
assert dmirror(frozenset({(0, 0), (1, 0), (1, 1)})) == frozenset({(0, 1), (1, 1), (0, 0)})
assert dmirror(frozenset({(0, 1), (1, 2)})) == frozenset({(0, 1), (1, 2)})
def test_cmirror():
assert cmirror(B) == ((1, 1, 1), (2, 0, 2))
assert cmirror(C) == ((5, 4), (5, 3))
assert cmirror(frozenset({(0, 0), (1, 1)})) == frozenset({(0, 0), (1, 1)})
assert cmirror(frozenset({(0, 0), (1, 0), (1, 1)})) == frozenset({(0, 0), (1, 0), (1, 1)})
assert cmirror(frozenset({(0, 1), (1, 2)})) == frozenset({(0, 1), (1, 2)})
def test_fill():
assert fill(B, 3, frozenset({(0, 0), (1, 1)})) == ((3, 1), (0, 3), (2, 1))
assert fill(C, 1, frozenset({(1, 0)})) == ((3, 4), (1, 5))
def test_paint():
assert paint(B, frozenset({(1, (0, 0)), (2, (1, 1))})) == ((1, 1), (0, 2), (2, 1))
assert paint(C, frozenset({(6, (1, 0))})) == ((3, 4), (6, 5))
def test_underfill():
assert underfill(C, 1, frozenset({(0, 0), (1, 0)})) == ((3, 4), (1, 5))
def test_underpaint():
assert underpaint(B, frozenset({(3, (0, 0)), (3, (1, 1))})) == ((2, 1), (0, 3), (2, 1))
assert underpaint(C, frozenset({(3, (1, 1))})) == ((3, 4), (5, 3))
def test_hupscale():
assert hupscale(B, 1) == B
assert hupscale(C, 1) == C
assert hupscale(B, 2) == ((2, 2, 1, 1), (0, 0, 1, 1), (2, 2, 1, 1))
assert hupscale(C, 2) == ((3, 3, 4, 4), (5, 5, 5, 5))
def test_vupscale():
assert vupscale(B, 1) == B
assert vupscale(C, 1) == C
assert vupscale(B, 2) == ((2, 1), (2, 1), (0, 1), (0, 1), (2, 1), (2, 1))
assert vupscale(C, 2) == ((3, 4), (3, 4), (5, 5), (5, 5))
def test_upscale():
assert upscale(B, 1) == B
assert upscale(C, 1) == C
assert upscale(B, 2) == ((2, 2, 1, 1), (2, 2, 1, 1), (0, 0, 1, 1), (0, 0, 1, 1), (2, 2, 1, 1), (2, 2, 1, 1))
assert upscale(C, 2) == ((3, 3, 4, 4), (3, 3, 4, 4), (5, 5, 5, 5), (5, 5, 5, 5))
assert upscale(frozenset({(3, (0, 1)), (4, (1, 0)), (5, (1, 1))}), 2) == frozenset({(3, (0, 2)), (3, (0, 3)), (3, (1, 2)), (3, (1, 3)), (4, (2, 0)), (4, (3, 0)), (4, (2, 1)), (4, (3, 1)), (5, (2, 2)), (5, (3, 2)), (5, (2, 3)), (5, (3, 3))})
assert upscale(frozenset({(3, (0, 0))}), 2) == frozenset({(3, (0, 0)), (3, (1, 0)), (3, (0, 1)), (3, (1, 1))})
def test_downscale():
assert downscale(B, 1) == B
assert downscale(C, 1) == C
assert downscale(((2, 2, 1, 1), (2, 2, 1, 1), (0, 0, 1, 1), (0, 0, 1, 1), (2, 2, 1, 1), (2, 2, 1, 1)), 2) == B
assert downscale(((3, 3, 4, 4), (3, 3, 4, 4), (5, 5, 5, 5), (5, 5, 5, 5)), 2) == C
def test_hconcat():
assert hconcat(A, B) == ((1, 0, 2, 1), (0, 1, 0, 1), (1, 0, 2, 1))
assert hconcat(B, A) == ((2, 1, 1, 0), (0, 1, 0, 1), (2, 1, 1, 0))
def test_vconcat():
assert vconcat(A, B) == ((1, 0), (0, 1), (1, 0), (2, 1), (0, 1), (2, 1))
assert vconcat(B, A) == ((2, 1), (0, 1), (2, 1), (1, 0), (0, 1), (1, 0))
assert vconcat(B, C) == ((2, 1), (0, 1), (2, 1), (3, 4), (5, 5))
def test_subgrid():
assert subgrid(frozenset({(3, (0, 0))}), C) == ((3,),)
assert subgrid(frozenset({(5, (1, 0)), (5, (1, 1))}), C) == ((5, 5),)
assert subgrid(frozenset({(2, (0, 1)), (4, (1, 0))}), D) == ((1, 2), (4, 5))
assert subgrid(frozenset({(1, (0, 0)), (0, (2, 2))}), D) == D
def test_hsplit():
assert hsplit(B, 1) == (B,)
assert hsplit(B, 2) == (((2,), (0,), (2,)), ((1,), (1,), (1,)))
assert hsplit(C, 1) == (C,)
assert hsplit(C, 2) == (((3,), (5,)), ((4,), (5,)))
def test_vsplit():
assert vsplit(B, 1) == (B,)
assert vsplit(B, 3) == (((2, 1),), ((0, 1),), ((2, 1),))
assert vsplit(C, 1) == (C,)
assert vsplit(C, 2) == (((3, 4),), ((5, 5),))
def test_cellwise():
assert cellwise(A, B, 0) == ((0, 0), (0, 1), (0, 0))
assert cellwise(C, E, 0) == ((0, 0), (0, 5))
def test_replace():
assert replace(B, 2, 3) == ((3, 1), (0, 1), (3, 1))
assert replace(C, 5, 0) == ((3, 4), (0, 0))
def test_switch():
assert switch(C, 3, 4) == ((4, 3), (5, 5))
def test_center():
assert center(frozenset({(1, (0, 0))})) == (0, 0)
assert center(frozenset({(1, (0, 0)), (1, (0, 2))})) == (0, 1)
assert center(frozenset({(1, (0, 0)), (1, (0, 2)), (1, (2, 0)), (1, (2, 2))})) == (1, 1)
def test_position():
assert position(frozenset({(0, (1, 1))}), frozenset({(0, (2, 2))})) == (1, 1)
assert position(frozenset({(0, (2, 2))}), frozenset({(0, (1, 2))})) == (-1, 0)
assert position(frozenset({(0, (3, 3))}), frozenset({(0, (3, 4))})) == (0, 1)
def test_index():
assert index(C, (0, 0)) == 3
assert index(D, (1, 2)) == 6
def test_canvas():
assert canvas(3, (1, 2)) == ((3, 3),)
assert canvas(2, (3, 1)) == ((2,), (2,), (2,))
def test_corners():
assert corners(frozenset({(1, 2), (0, 3), (4, 0)})) == frozenset({(0, 0), (0, 3), (4, 0), (4, 3)})
assert corners(frozenset({(1, 2), (0, 0), (4, 3)})) == frozenset({(0, 0), (0, 3), (4, 0), (4, 3)})
def test_connect():
assert connect((1, 1), (2, 2)) == frozenset({(1, 1), (2, 2)})
assert connect((1, 1), (1, 4)) == frozenset({(1, 1), (1, 2), (1, 3), (1, 4)})
def test_cover():
assert cover(C, frozenset({(0, 0)})) == ((5, 4), (5, 5))
def test_trim():
assert trim(D) == ((5,),)
def test_move():
assert move(C, frozenset({(3, (0, 0))}), (1, 1)) == ((5, 4), (5, 3))
def test_tophalf():
assert tophalf(C) == ((3, 4),)
assert tophalf(D) == ((1, 2, 3),)
def test_bottomhalf():
assert bottomhalf(C) == ((5, 5),)
assert bottomhalf(D) == ((7, 8, 0),)
def test_lefthalf():
assert lefthalf(C) == ((3,), (5,))
assert lefthalf(D) == ((1,), (4,), (7,))
def test_righthalf():
assert righthalf(C) == ((4,), (5,))
assert righthalf(D) == ((3,), (6,), (0,))
def test_vfrontier():
assert vfrontier((3, 4)) == frozenset({(i, 4) for i in range(30)})
def test_hfrontier():
assert hfrontier((3, 4)) == frozenset({(3, i) for i in range(30)})
def test_backdrop():
assert backdrop(frozenset({(2, 3), (3, 2), (3, 3), (4, 1)})) == frozenset({(2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3), (4, 1), (4, 2), (4, 3),})
def test_delta():
assert delta(frozenset({(2, 3), (3, 2), (3, 3), (4, 1)})) == frozenset({(2, 1), (2, 2), (3, 1), (4, 2), (4, 3)})
def test_gravitate():
assert gravitate(frozenset({(0, 0)}), frozenset({(0, 1)})) == (0, 0)
assert gravitate(frozenset({(0, 0)}), frozenset({(0, 4)})) == (0, 3)
def test_inbox():
assert inbox(frozenset({(0, 0), (2, 2)})) == frozenset({(1, 1)})
def test_outbox():
assert outbox(frozenset({(1, 1)})) == frozenset({(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)})
def test_box():
assert box(frozenset({(0, 0), (1, 1)})) == frozenset({(0, 0), (0, 1), (1, 0), (1, 1)})
def test_shoot():
assert shoot((0, 0), (1, 1)) == frozenset({(i, i) for i in range(43)})
def test_occurrences():
assert occurrences(G, frozenset({(1, (0, 0)), (1, (0, 1))})) == frozenset({(1, 1), (2, 1)})
def test_frontiers():
assert frontiers(C) == frozenset({frozenset({(5, (1, 0)), (5, (1, 1))})})
def test_compress():
assert compress(K) == ((0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0))
def test_hperiod():
assert hperiod(frozenset({(8, (2, 1)), (8, (1, 3)), (2, (2, 4)), (8, (2, 3)), (2, (2, 2)), (2, (1, 2)), (8, (1, 1)), (8, (1, 5)), (2, (1, 4)), (8, (2, 5)), (2, (2, 0)), (2, (1, 0))})) == 2
assert hperiod(frozenset({(2, (2, 6)), (2, (2, 0)), (3, (2, 4)), (3, (2, 2)), (3, (2, 5)), (2, (2, 3)), (3, (2, 1))})) == 3
def test_vperiod():
assert vperiod(frozenset({(2, (2, 6)), (2, (2, 0)), (3, (2, 4)), (3, (2, 2)), (3, (2, 5)), (2, (2, 3)), (3, (2, 1))})) == 1
assert vperiod(frozenset({(1, (2, 6)), (2, (3, 5)), (2, (3, 0)), (2, (2, 2)), (2, (2, 7)), (1, (3, 4)), (2, (2, 1)), (1, (2, 3)), (2, (2, 5)), (2, (2, 4)), (1, (3, 7)), (1, (2, 0)), (2, (3, 6)), (2, (3, 2)), (2, (3, 3)), (1, (3, 1))})) == 2