summaryrefslogtreecommitdiffstats
path: root/tests/016/arith.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-09 23:58:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-09 23:58:55 -0700
commit00b6397408934f95c16f3fa33959fb17e34f63c9 (patch)
tree0d1a30809b17dae750bb0216511c0129e54f3e8b /tests/016/arith.tl
parent864d1c6fe182661a7bd7d4eda928f8a19318b651 (diff)
downloadtxr-00b6397408934f95c16f3fa33959fb17e34f63c9.tar.gz
txr-00b6397408934f95c16f3fa33959fb17e34f63c9.tar.bz2
txr-00b6397408934f95c16f3fa33959fb17e34f63c9.zip
arith: switch sum and prod to seq_iter.
* arith.c (nary_op_keyfun): Static function removed. (nary_op_seq, nary_op_seq_keyfun): New static functions. (sumv, prodv): Static functions removed. (sum, prod): Reimplement using nary_op_seq and nary_op_seq_keyfun. Conversion of sequence to list smuggled via args is gone. * tests/016/arith.tl: new sum and prod tests. * txr.1: Note about sum and prod taking an iterable sequence added.
Diffstat (limited to 'tests/016/arith.tl')
-rw-r--r--tests/016/arith.tl24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/016/arith.tl b/tests/016/arith.tl
index 43efb6bb..52e8667b 100644
--- a/tests/016/arith.tl
+++ b/tests/016/arith.tl
@@ -142,3 +142,27 @@
(test (ffi-get (ffi-put #x-8000000000000000 (ffi int64)) (ffi int64))
#x-8000000000000000)
+
+(mtest
+ (sum #()) 0
+ (sum #(1)) 1
+ (sum #(1 2)) 3
+ (sum #(1 2 3)) 6
+ (sum #() (op * 10)) 0
+ (sum #(1) (op * 10)) 10
+ (sum #(1 2) (op * 10)) 30
+ (sum #(1 2 3) (op * 10)) 60
+ (sum 1..10) 45
+ (sum 2..10) 44)
+
+(mtest
+ (prod #()) 1
+ (prod #(1)) 1
+ (prod #(1 2)) 2
+ (prod #(1 2 3)) 6
+ (prod #() (op * 10)) 1
+ (prod #(1) (op * 10)) 10
+ (prod #(1 2) (op * 10)) 200
+ (prod #(1 2 3) (op * 10)) 6000
+ (prod 2..8) 5040
+ (prod 3..8) 2520)