summaryrefslogtreecommitdiffstats
path: root/tests/016/arith.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-01-11 21:14:24 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-01-11 21:14:24 -0800
commit2e0f7c370fa5012cb54328eb0e73412cb3c59351 (patch)
tree4b7db988ad507f7a42e6be599a5cc601c9dd4260 /tests/016/arith.tl
parentef0c40c134bfbef21dc57eadc1b32bc1f08ee670 (diff)
downloadtxr-2e0f7c370fa5012cb54328eb0e73412cb3c59351.tar.gz
txr-2e0f7c370fa5012cb54328eb0e73412cb3c59351.tar.bz2
txr-2e0f7c370fa5012cb54328eb0e73412cb3c59351.zip
sum-each, mul-each: handle no vars case.
* stdlib/arith-each.tl (sys:arith-each): If there are no vars, then just reduce to the identity element value. This is alreading happening fine for the each-prod family of operators. * tests/016/arith.tl: Test cases covering the no vars and empty iteration identity element cases for sum-each and mul-each, as well as the *-prod variants. * txr.1: Document empty iteration and empty vars behavior for arithmetic each operators as well as the each-prod family.
Diffstat (limited to 'tests/016/arith.tl')
-rw-r--r--tests/016/arith.tl20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/016/arith.tl b/tests/016/arith.tl
index ad919e6b..24521921 100644
--- a/tests/016/arith.tl
+++ b/tests/016/arith.tl
@@ -255,10 +255,18 @@
1.5 2.25 2.625 2.8125 2.90625))
(mtest
+ (sum-each ())
+ 0
+ (sum-each ((x nil)))
+ 0
(sum-each ((x '(1 2 3))
(y '(4 5 6)))
(* x y))
32
+ (mul-each ())
+ 1
+ (mul-each ((x nil)))
+ 1
(mul-each ((x '(1 2 3))
(y '(4 5 6)))
(+ x y))
@@ -281,6 +289,12 @@
:error)
(mtest
+ (sum-each-prod ())
+ 0
+ (sum-each-prod ((x nil)))
+ 0
+ (sum-each-prod ((x '(4))) x)
+ 4
(sum-each-prod ((x '(1 2 3))
(y '(4 3 2)))
(* x y))
@@ -295,6 +309,12 @@
:error)
(mvtest
+ (mul-each-prod ())
+ 1
+ (mul-each-prod ((x nil)))
+ 1
+ (mul-each-prod ((x '(4))) x)
+ 4
(mul-each-prod ((x '(1 2 3))
(y '(4 3 2)))
(+ x y))