Skip to content

Commit e6d8dd1

Browse files
committed
Initial version of thorough (^) (symmetric difference) tests
1 parent c518b59 commit e6d8dd1

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
use v6;
2+
use Test;
3+
4+
# This test file tests the following set operators:
5+
# (^) set symmetric difference (Texas)
6+
# ⊖ set symmetric difference
7+
8+
# Empty mutables that have the internal hash allocated
9+
(my $esh = <a>.SetHash)<a>:delete;
10+
(my $ebh = <a>.BagHash)<a>:delete;
11+
(my $emh = <a>.MixHash)<a>:delete;
12+
13+
my @types = Set, SetHash, Bag, BagHash, Mix, MixHash;
14+
15+
# single parameter, result
16+
my @pairs =
17+
<a b c>.Set, <a b c>.Set,
18+
<a b c>.SetHash, <a b c>.Set,
19+
<a b c>.Bag, <a b c>.Bag,
20+
<a b c>.BagHash, <a b c>.Bag,
21+
<a b c>.Mix, <a b c>.Mix,
22+
<a b c>.MixHash, <a b c>.Mix,
23+
{:42a}, <a>.Set,
24+
{:42a,:0b}, <a>.Set,
25+
:{:42a}, <a>.Set,
26+
:{:42a,:0b}, <a>.Set,
27+
<a b c>, <a b c>.Set,
28+
("a","b",:0c), <a b>.Set,
29+
42, 42.Set,
30+
:0b, set(),
31+
;
32+
33+
my @triplets =
34+
35+
# result should be a Set
36+
set(), set(), set(),
37+
SetHash.new, SetHash.new, set(),
38+
$esh, $esh, set(),
39+
<a b>.Set, set(), <a b>.Set,
40+
<a b>.SetHash, set(), <a b>.Set,
41+
<a b>.Set, <a b>.Set, set(),
42+
<a b>.SetHash, <a b>.SetHash, set(),
43+
<a b>.Set, <c d>.Set, <a b c d>.Set,
44+
<a b c>.Set, <b c d>.Set, <a d>.Set,
45+
<a b>.SetHash, <c d>.SetHash, <a b c d>.Set,
46+
<a b c>.SetHash, <b c d>.SetHash, <a d>.Set,
47+
48+
# result should be a Bag
49+
bag(), bag(), bag(),
50+
BagHash.new, BagHash.new, bag(),
51+
$ebh, $ebh, bag(),
52+
<a b b>.Bag, bag(), <a b b>.Bag,
53+
<a b b>.BagHash, bag(), <a b b>.Bag,
54+
<a b b>.Bag, <a b>.Bag, <b>.Bag,
55+
<a b b>.BagHash, <a b>.BagHash, <b>.Bag,
56+
<a b b>.Bag, <c d>.Bag, <a b b c d>.Bag,
57+
<a b b c>.Bag, <b c d>.Bag, <a b d>.Bag,
58+
<a b b>.BagHash, <c d>.BagHash, <a b b c d>.Bag,
59+
<a b b c>.BagHash, <b c d>.BagHash, <a b d>.Bag,
60+
61+
# result should be a Mix
62+
mix(), mix(), mix(),
63+
MixHash.new, MixHash.new, mix(),
64+
$emh, $emh, mix(),
65+
mix(), <a b>.Mix, <a b>.Mix,
66+
MixHash.new, <a b>.MixHash, <a b>.Mix,
67+
(a=>pi,b=>tau).Mix, mix(), (a=>pi,b=>tau).Mix,
68+
(a=>pi,b=>tau).MixHash, mix(), (a=>pi,b=>tau).Mix,
69+
(a=>pi,b=>tau).Mix, <a b>.Mix, (a=>(pi-1),b=>(tau-1)).Mix,
70+
(a=>pi,b=>tau).MixHash, <a b>.MixHash, (a=>(pi-1),b=>(tau-1)).Mix,
71+
(a=>pi,b=>tau).Mix, <c d>.Mix, (a=>pi,b=>tau,:c,:d).Mix,
72+
(a=>pi,b=>tau).Mix, <b c>.Mix, (a=>pi,b=>(tau-1),:c).Mix,
73+
(a=>pi,b=>tau).MixHash, <c d>.MixHash, (a=>pi,b=>tau,:c,:d).Mix,
74+
(a=>pi,b=>tau).MixHash, <b c>.MixHash, (a=>pi,b=>(tau-1),:c).Mix,
75+
76+
# coercions
77+
<a b>.Set, <a b b>.Bag, <b>.Bag,
78+
<a b>.SetHash, <a b b>.BagHash, <b>.Bag,
79+
80+
<a b>.Set, <a b b>.Mix, <b>.Mix,
81+
<a b>.SetHash, <a b b>.MixHash, <b>.Mix,
82+
83+
<a b>.Set, (b=>-1).Mix, <a b b>.Mix,
84+
<a b>.SetHash, (b=>-1).MixHash, <a b b>.Mix,
85+
86+
<a b>.Bag, <a b b>.Mix, <b>.Mix,
87+
<a b>.BagHash, <a b b>.MixHash, <b>.Mix,
88+
89+
<a b>.Bag, (b=>-1).Mix, <a b b>.Mix,
90+
<a b>.BagHash, (b=>-1).MixHash, <a b b>.Mix,
91+
92+
<a b c>.Set, {:42a,:0b}, <b c>.Set,
93+
<a b c>.SetHash, {:42a,:0b}, <b c>.Set,
94+
<a b b c>.Bag, {:42a,:0b}, (:41a,:2b,:c).Bag,
95+
<a b b c>.BagHash, {:42a,:0b}, (:41a,:2b,:c).Bag,
96+
<a b b c>.Mix, {:42a,:0b}, (:41a,:2b,:c).Mix,
97+
<a b b c>.MixHash, {:42a,:0b}, (:41a,:2b,:c).Mix,
98+
99+
{:42a,:0b}, <a b c>.Set, <b c>.Set,
100+
{:42a,:0b}, <a b c>.SetHash, <b c>.Set,
101+
{:42a,:0b}, <a b b c>.Bag, (:41a,:2b,:c).Bag,
102+
{:42a,:0b}, <a b b c>.BagHash, (:41a,:2b,:c).Bag,
103+
{:42a,:0b}, <a b b c>.Mix, (:41a,:2b,:c).Mix,
104+
{:42a,:0b}, <a b b c>.MixHash, (:41a,:2b,:c).Mix,
105+
106+
<a b c>.Set, <a b c d>, <d>.Set,
107+
<a b c>.SetHash, <a b c d>, <d>.Set,
108+
<a b b c>.Bag, <a b c d>, <b d>.Bag,
109+
<a b b c>.BagHash, <a b c d>, <b d>.Bag,
110+
<a b b c>.Mix, <a b c d>, <b d>.Mix,
111+
<a b b c>.MixHash, <a b c d>, <b d>.Mix,
112+
113+
<a b c d>, <a b c e>.Set, <d e>.Set,
114+
<a b c d>, <a b c e>.SetHash, <d e>.Set,
115+
<a b c d>, <a b c e>.Bag, <d e>.Bag,
116+
<a b c d>, <a b c e>.BagHash, <d e>.Bag,
117+
<a b c d>, <a b c e>.Mix, <d e>.Mix,
118+
<a b c d>, <a b c e>.MixHash, <d e>.Mix,
119+
120+
<a b c>, <c d e>, <a b d e>.Set,
121+
(:42a,:0b,:c), (:c,:42d,"e"), <a d e>.Set,
122+
(:b,:c,:42d,"e"), (:42a,:0b,:c), <a b d e>.Set,
123+
(:42a,:0b), (:a,:42d,"e"), <d e>.Set,
124+
{:42a,:0b}, {:a,:c,:42d}, <c d>.Set,
125+
:{42=>"a",666=>""}, :{55=>"c",66=>1}, (42,55,66).Set,
126+
:{42=>"a",666=>""}, :{55=>"c",666=>1}, (42,55,666).Set,
127+
:{42=>"a",666=>""}, :{42=>"c",666=>1}, 666.Set,
128+
:{42=>"a",666=>""}, {:c,:42d}, (42,"c","d").Set,
129+
:{a=>42,666=>""}, {:a,:42d}, <d>.Set,
130+
{:42a,:0b}, <c d e>, <a c d e>.Set,
131+
{:42a,:0b}, <a d e>, <d e>.Set,
132+
:{42=>"a",666=>""}, <a b c>, (42,"a","b","c").Set,
133+
:{a=>42,666=>""}, <a b c>, <b c>.Set,
134+
42, 666, (42,666).Set,
135+
;
136+
137+
plan 2 * (1 + @pairs/2 + 2 * @triplets/3) + @types * 2;
138+
139+
# symmetrc difference
140+
for
141+
&infix:<(^)>, "(^)",
142+
&infix:<>, ""
143+
-> &op, $name {
144+
145+
is-deeply op(), set(), "does $name\() return set()";
146+
147+
for @pairs -> $parameter, $result {
148+
#exit dd $parameter, $result unless
149+
is-deeply op($parameter.item), $result,
150+
"infix:<$name>(|$parameter.gist())";
151+
}
152+
153+
for @triplets -> $left, $right, $result {
154+
#exit dd $left, $right, $result unless
155+
is-deeply op($left,$right), $result,
156+
"$left.gist() $name $right.gist()";
157+
#exit dd $right, $left, $result unless
158+
is-deeply op($right,$left), $result,
159+
"$right.gist() $name $left.gist()";
160+
}
161+
}
162+
163+
for @types -> \qh {
164+
throws-like { qh.new (^) ^Inf }, X::Cannot::Lazy,
165+
"Cannot {qh.perl}.new (-) lazy list";
166+
throws-like { qh.new(<a b c>) (^) ^Inf }, X::Cannot::Lazy,
167+
"Cannot {qh.perl}.new(<a b c>) (-) lazy list";
168+
}
169+
170+
# vim: ft=perl6

0 commit comments

Comments
 (0)