Skip to content

Commit 695cd7e

Browse files
committed
Add unit tests for parallel assignment
1 parent 9eec940 commit 695cd7e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

M2/Macaulay2/tests/normal/parallel.m2

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,115 @@
1+
-- global variales
12
(a,b,c) = (4,5,6)
23
assert( a == 4 and b == 5 and c == 6 )
4+
5+
-- local variables
6+
g = () -> (
7+
(a, b, c) := (7, 8, 9);
8+
assert Equation(a, 7);
9+
assert Equation(b, 8);
10+
assert Equation(c, 9))
11+
g()
12+
assert Equation(a, 4)
13+
assert Equation(b, 5)
14+
assert Equation(c, 6)
15+
16+
-- thread local variables
17+
threadLocal d
18+
threadLocal e
19+
threadLocal f
20+
t = schedule(() -> (
21+
(d, e, f) = (10, 11, 12);
22+
d == 10 and e == 11 and f == 12))
23+
assert taskResult t
24+
assertNull = x -> assert BinaryOperation(symbol ===, x, null)
25+
assertNull d
26+
assertNull e
27+
assertNull f
28+
29+
-- binary
30+
x = new MutableHashTable
31+
(x.foo, x#0) = (1, 2)
32+
assert Equation(x.foo, 1)
33+
assert Equation(x#0, 2)
34+
35+
X = new Type of HashTable
36+
(X + X, X - X) := ((x, y) -> 3, (x, y) -> 4)
37+
(x, y) = (new X, new X)
38+
assert Equation(x + y, 3)
39+
assert Equation(x - y, 4)
40+
41+
(X + X, X - X) = ((x, y, e) -> 5, (x, y, e) -> 6)
42+
assert Equation(x + y = 7, 5)
43+
assert Equation(x - y = 8, 6)
44+
45+
-- adjacent
46+
foo = method()
47+
(foo ZZ, foo(QQ, RR), X X) := (x -> 9, (x, y) -> 10, (x, y) -> 11)
48+
assert Equation(foo 11, 9)
49+
assert Equation(foo(1/2, 3.14159), 10)
50+
assert Equation(x y, 11)
51+
52+
bar = memoize(x -> x^2)
53+
(bar 0, X X) = (12, (x, y, e) -> 13)
54+
assert Equation(bar 0, 12)
55+
assert Equation(x y = 14, 13)
56+
57+
-- unary
58+
(+X, X~) := (x -> 15, x -> 16)
59+
assert Equation(+x, 15)
60+
assert Equation(x~, 16)
61+
62+
(+X, X~) = ((x, e) -> 17, (x, e) -> 18)
63+
assert Equation(+x = 19, 17)
64+
assert Equation(x~ = 20, 18)
65+
66+
-- new
67+
(new X, new X from ZZ, new X of X, new X of X from ZZ) := (
68+
T -> new T from {a => 1},
69+
(T,n) -> new T from {a => n},
70+
(S,T) -> new S from {a => 2},
71+
(S,T,n) -> new S from {a => 2*n})
72+
x = new X
73+
assert Equation(x.a, 1)
74+
x = new X from 3
75+
assert Equation(x.a, 3)
76+
x = new X of X
77+
assert Equation(x.a, 2)
78+
x = new X of X from 3
79+
assert Equation(x.a, 6)
80+
81+
-- recursive parallel assignment
82+
((a, b), {c, d}, [e, f], <|g, h|>) = ((1, 2), (3, 4), (5, 6), (7, 8))
83+
assert Equation(a, 1)
84+
assert Equation(b, 2)
85+
assert Equation(c, 3)
86+
assert Equation(d, 4)
87+
assert Equation(e, 5)
88+
assert Equation(f, 6)
89+
assert Equation(g, 7)
90+
assert Equation(h, 8)
91+
92+
-- null
93+
(a, , , b) = (9, 10, 11, 12)
94+
assert Equation(a, 9)
95+
assert Equation(b, 12)
96+
97+
-- augmented
98+
(x, y, z) = (1, 2, 3)
99+
(x, y, z) += (4, 5, 6)
100+
assert Equation(x, 5)
101+
assert Equation(y, 7)
102+
assert Equation(z, 9)
103+
104+
-- (x) = y should behave like x = y
105+
assert Equation((x) = 5, 5)
106+
assert Equation((x) += 2, 7)
107+
108+
-- 0-length LHS
109+
assert Equation(() = (), ())
110+
assert Equation(() := (), ())
111+
assert Equation(() += (), ())
112+
3113
end
4114
-- Local Variables:
5115
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages/Macaulay2Doc/test parallel.out"

0 commit comments

Comments
 (0)