summaryrefslogtreecommitdiff
path: root/tests/typ
diff options
context:
space:
mode:
authorSekoiaTree <51149447+SekoiaTree@users.noreply.github.com>2023-04-25 11:18:27 +0200
committerGitHub <noreply@github.com>2023-04-25 11:18:27 +0200
commitefad1e71fa699e0d2413d3a6a3ce5a4163e38112 (patch)
tree64dd37c540989e71408ee005abdccdb523d76618 /tests/typ
parent12129f01707a3389ef90a4c78a872e1c7897a752 (diff)
Add sum and product to arrays (#966)
Diffstat (limited to 'tests/typ')
-rw-r--r--tests/typ/compiler/array.typ21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/typ/compiler/array.typ b/tests/typ/compiler/array.typ
index c9e85ed7..c52160b0 100644
--- a/tests/typ/compiler/array.typ
+++ b/tests/typ/compiler/array.typ
@@ -167,6 +167,27 @@
#(1, 2, 3).fold(0, () => none)
---
+// Test the `sum` method.
+#test(().sum(default: 0), 0)
+#test(().sum(default: []), [])
+#test((1, 2, 3).sum(), 6)
+
+---
+// Error: 2-10 cannot calculate sum of empty array with no default
+#().sum()
+
+---
+// Test the `product` method.
+#test(().product(default: 0), 0)
+#test(().product(default: []), [])
+#test(([ab], 3).product(), [ab]*3)
+#test((1, 2, 3).product(), 6)
+
+---
+// Error: 2-14 cannot calculate product of empty array with no default
+#().product()
+
+---
// Test the `rev` method.
#test(range(3).rev(), (2, 1, 0))