From efad1e71fa699e0d2413d3a6a3ce5a4163e38112 Mon Sep 17 00:00:00 2001 From: SekoiaTree <51149447+SekoiaTree@users.noreply.github.com> Date: Tue, 25 Apr 2023 11:18:27 +0200 Subject: Add sum and product to arrays (#966) --- tests/typ/compiler/array.typ | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/typ/compiler/array.typ') 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 @@ -166,6 +166,27 @@ // Error: 20-22 unexpected argument #(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)) -- cgit v1.2.3