Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Jan 14, 2025
1 parent 541f268 commit 315ab99
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
17 changes: 17 additions & 0 deletions test/library/standard/Map/reduceOverKeysAndValues.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use Map;

var m: map(int, int);

for i in 1..100 do m[i] = i;

{
var s = 0;
forall k in m.keys() with (+ reduce s) do s += k;
writeln(s);
}

{
var s = 0;
forall v in m.values() with (+ reduce s) do s += v;
writeln(s);
}
2 changes: 2 additions & 0 deletions test/library/standard/Map/reduceOverKeysAndValues.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5050
5050
32 changes: 29 additions & 3 deletions test/library/standard/Map/testIterators.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,42 @@ var A: [1..fac.size] (int, FacInt);
for item in zip(fac.keys(), fac.values()) {
A[item(0)] = item;
}
writeln(sorted(A));
writeln("A: ", sorted(A));

var B: [1..fac.size] FacInt;
for (val, i) in zip(fac.values(), 1..) {
B[i] = val;
}
writeln(sorted(B));
writeln("B: ", sorted(B));

var C: [1..fac.size] (int, FacInt);
for key in fac.keys() {
C[key] = (key, fac[key]);
}
writeln(sorted(C));
writeln("C: ", sorted(C));

var D: [1..fac.size] (int, FacInt);
forall item in zip(fac.keys(), fac.values()) {
D[item(0)] = item;
}
writeln("D: ", sorted(D));

var E: [1..fac.size] (FacInt, int);
forall item in zip(fac.values(), fac.keys()) {
E[item(1)] = item;
}
writeln("E: ", sorted(E));

var F: [1..fac.size] (int, FacInt);
forall key in fac.keys() {
F[key] = (key, fac[key]);
}
writeln("F: ", sorted(F));

var G: [1..fac.size] FacInt;
var Hidx: atomic int = 1;
forall val in fac.values() {
var i = Hidx.fetchAdd(1);
G[i] = val;
}
writeln("G: ", sorted(G));
10 changes: 7 additions & 3 deletions test/library/standard/Map/testIterators.good
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
(1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
(n = 1, nFac = 1) (n = 2, nFac = 2) (n = 3, nFac = 6) (n = 4, nFac = 24) (n = 5, nFac = 120) (n = 6, nFac = 720) (n = 7, nFac = 5040) (n = 8, nFac = 40320) (n = 9, nFac = 362880) (n = 10, nFac = 3628800) (n = 11, nFac = 39916800) (n = 12, nFac = 479001600) (n = 13, nFac = 6227020800) (n = 14, nFac = 87178291200) (n = 15, nFac = 1307674368000)
(1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
A: (1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
B: (n = 1, nFac = 1) (n = 2, nFac = 2) (n = 3, nFac = 6) (n = 4, nFac = 24) (n = 5, nFac = 120) (n = 6, nFac = 720) (n = 7, nFac = 5040) (n = 8, nFac = 40320) (n = 9, nFac = 362880) (n = 10, nFac = 3628800) (n = 11, nFac = 39916800) (n = 12, nFac = 479001600) (n = 13, nFac = 6227020800) (n = 14, nFac = 87178291200) (n = 15, nFac = 1307674368000)
C: (1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
D: (1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
E: ((n = 1, nFac = 1), 1) ((n = 2, nFac = 2), 2) ((n = 3, nFac = 6), 3) ((n = 4, nFac = 24), 4) ((n = 5, nFac = 120), 5) ((n = 6, nFac = 720), 6) ((n = 7, nFac = 5040), 7) ((n = 8, nFac = 40320), 8) ((n = 9, nFac = 362880), 9) ((n = 10, nFac = 3628800), 10) ((n = 11, nFac = 39916800), 11) ((n = 12, nFac = 479001600), 12) ((n = 13, nFac = 6227020800), 13) ((n = 14, nFac = 87178291200), 14) ((n = 15, nFac = 1307674368000), 15)
F: (1, (n = 1, nFac = 1)) (2, (n = 2, nFac = 2)) (3, (n = 3, nFac = 6)) (4, (n = 4, nFac = 24)) (5, (n = 5, nFac = 120)) (6, (n = 6, nFac = 720)) (7, (n = 7, nFac = 5040)) (8, (n = 8, nFac = 40320)) (9, (n = 9, nFac = 362880)) (10, (n = 10, nFac = 3628800)) (11, (n = 11, nFac = 39916800)) (12, (n = 12, nFac = 479001600)) (13, (n = 13, nFac = 6227020800)) (14, (n = 14, nFac = 87178291200)) (15, (n = 15, nFac = 1307674368000))
G: (n = 1, nFac = 1) (n = 2, nFac = 2) (n = 3, nFac = 6) (n = 4, nFac = 24) (n = 5, nFac = 120) (n = 6, nFac = 720) (n = 7, nFac = 5040) (n = 8, nFac = 40320) (n = 9, nFac = 362880) (n = 10, nFac = 3628800) (n = 11, nFac = 39916800) (n = 12, nFac = 479001600) (n = 13, nFac = 6227020800) (n = 14, nFac = 87178291200) (n = 15, nFac = 1307674368000)

0 comments on commit 315ab99

Please sign in to comment.