summaryrefslogtreecommitdiffstats
path: root/tests/015
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-12-27 15:08:39 -0800
committerKaz Kylheku <kaz@kylheku.com>2023-12-27 15:08:39 -0800
commitb8dd7f02e01072c928ffa7a37b662ab1644faeaa (patch)
tree2ab3b6f3db5a6e4bbf8ef09dc0bce461853d53e8 /tests/015
parentd63dea84e50579d61af4cc5975acc92f2d71b3d9 (diff)
downloadtxr-b8dd7f02e01072c928ffa7a37b662ab1644faeaa.tar.gz
txr-b8dd7f02e01072c928ffa7a37b662ab1644faeaa.tar.bz2
txr-b8dd7f02e01072c928ffa7a37b662ab1644faeaa.zip
rcomb, perm, rperm: test.
* tests/015/comb.tl: New tests.
Diffstat (limited to 'tests/015')
-rw-r--r--tests/015/comb.tl317
1 files changed, 317 insertions, 0 deletions
diff --git a/tests/015/comb.tl b/tests/015/comb.tl
index c60b8f2a..b0cdf277 100644
--- a/tests/015/comb.tl
+++ b/tests/015/comb.tl
@@ -23,6 +23,47 @@
(otype (normtype (first out))))
(vtest stype otype)))))
+(defun test-rcomb (s k)
+ (let ((out (rcomb s k))
+ (nCk (n-choose-k (+ (len s) k -1) k)))
+ (if (and (empty s) (plusp k))
+ (test out nil)
+ (mvtest
+ (len out) nCk
+ (len (uniq out)) nCk))
+ (vtest
+ (sort out) out)
+ (unless (empty out)
+ (let ((stype (normtype s))
+ (otype (normtype (first out))))
+ (vtest stype otype)))))
+
+(defun test-perm (s k)
+ (let ((out (perm s k))
+ (nPk (n-perm-k (len s) k)))
+ (if (> k (len s))
+ (test out nil)
+ (mvtest
+ (len out) nPk
+ (len (uniq out)) nPk))
+ (unless (empty out)
+ (let ((stype (normtype s))
+ (otype (normtype (first out))))
+ (vtest stype otype)))))
+
+(defun test-rperm (s k)
+ (let ((out (rperm s k))
+ (exp (expt (len s) k)))
+ (mvtest
+ (len out) exp
+ (len (uniq out)) exp)
+ (vtest
+ (sort out) out)
+ (unless (empty out)
+ (let ((stype (normtype s))
+ (otype (normtype (first out))))
+ (vtest stype otype)))))
+
(test-comb #() 0)
(test-comb #() 1)
(test-comb #(1) 0)
@@ -114,3 +155,279 @@
(comb '(1) -1) :error
(comb "" -1) :error
(comb "a" -1) :error)
+
+(test-rcomb #() 0)
+(test-rcomb #() 1)
+(test-rcomb #(1) 0)
+(test-rcomb #(1) 1)
+(test-rcomb #(1) 2)
+(test-rcomb #(1 2) 0)
+(test-rcomb #(1 2) 1)
+(test-rcomb #(1 2) 2)
+(test-rcomb #(1 2) 3)
+(test-rcomb #(1 2 3) 0)
+(test-rcomb #(1 2 3) 1)
+(test-rcomb #(1 2 3) 2)
+(test-rcomb #(1 2 3) 3)
+(test-rcomb #(1 2 3) 4)
+(test-rcomb #(1 2 3 4) 0)
+(test-rcomb #(1 2 3 4) 1)
+(test-rcomb #(1 2 3 4) 2)
+(test-rcomb #(1 2 3 4) 3)
+(test-rcomb #(1 2 3 4) 4)
+(test-rcomb #(1 2 3 4) 5)
+(test-rcomb #(1 2 3 4 5) 0)
+(test-rcomb #(1 2 3 4 5) 1)
+(test-rcomb #(1 2 3 4 5) 2)
+(test-rcomb #(1 2 3 4 5) 3)
+(test-rcomb #(1 2 3 4 5) 4)
+(test-rcomb #(1 2 3 4 5) 5)
+(test-rcomb #(1 2 3 4 5) 5)
+
+(test-rcomb '() 0)
+(test-rcomb '() 1)
+(test-rcomb '(1) 0)
+(test-rcomb '(1) 1)
+(test-rcomb '(1) 2)
+(test-rcomb '(1 2) 0)
+(test-rcomb '(1 2) 1)
+(test-rcomb '(1 2) 2)
+(test-rcomb '(1 2) 3)
+(test-rcomb '(1 2 3) 0)
+(test-rcomb '(1 2 3) 1)
+(test-rcomb '(1 2 3) 2)
+(test-rcomb '(1 2 3) 3)
+(test-rcomb '(1 2 3) 4)
+(test-rcomb '(1 2 3 4) 0)
+(test-rcomb '(1 2 3 4) 1)
+(test-rcomb '(1 2 3 4) 2)
+(test-rcomb '(1 2 3 4) 3)
+(test-rcomb '(1 2 3 4) 4)
+(test-rcomb '(1 2 3 4) 5)
+(test-rcomb '(1 2 3 4 5) 0)
+(test-rcomb '(1 2 3 4 5) 1)
+(test-rcomb '(1 2 3 4 5) 2)
+(test-rcomb '(1 2 3 4 5) 3)
+(test-rcomb '(1 2 3 4 5) 4)
+(test-rcomb '(1 2 3 4 5) 5)
+(test-rcomb '(1 2 3 4 5) 5)
+
+(test-rcomb "" 0)
+(test-rcomb "" 1)
+(test-rcomb "1" 0)
+(test-rcomb "1" 1)
+(test-rcomb "1" 2)
+(test-rcomb "12" 0)
+(test-rcomb "12" 1)
+(test-rcomb "12" 2)
+(test-rcomb "12" 3)
+(test-rcomb "123" 0)
+(test-rcomb "123" 1)
+(test-rcomb "123" 2)
+(test-rcomb "123" 3)
+(test-rcomb "123" 4)
+(test-rcomb "1234" 0)
+(test-rcomb "1234" 1)
+(test-rcomb "1234" 2)
+(test-rcomb "1234" 3)
+(test-rcomb "1234" 4)
+(test-rcomb "1234" 5)
+(test-rcomb "12345" 0)
+(test-rcomb "12345" 1)
+(test-rcomb "12345" 2)
+(test-rcomb "12345" 3)
+(test-rcomb "12345" 4)
+(test-rcomb "12345" 5)
+(test-rcomb "12345" 5)
+
+(mtest
+ (rcomb #() -1) :error
+ (rcomb #(1) -1) :error
+ (rcomb () -1) :error
+ (rcomb '(1) -1) :error
+ (rcomb "" -1) :error
+ (rcomb "a" -1) :error)
+
+(test-perm #() 0)
+(test-perm #() 1)
+(test-perm #(1) 0)
+(test-perm #(1) 1)
+(test-perm #(1) 2)
+(test-perm #(1 2) 0)
+(test-perm #(1 2) 1)
+(test-perm #(1 2) 2)
+(test-perm #(1 2) 3)
+(test-perm #(1 2 3) 0)
+(test-perm #(1 2 3) 1)
+(test-perm #(1 2 3) 2)
+(test-perm #(1 2 3) 3)
+(test-perm #(1 2 3) 4)
+(test-perm #(1 2 3 4) 0)
+(test-perm #(1 2 3 4) 1)
+(test-perm #(1 2 3 4) 2)
+(test-perm #(1 2 3 4) 3)
+(test-perm #(1 2 3 4) 4)
+(test-perm #(1 2 3 4) 5)
+(test-perm #(1 2 3 4 5) 0)
+(test-perm #(1 2 3 4 5) 1)
+(test-perm #(1 2 3 4 5) 2)
+(test-perm #(1 2 3 4 5) 3)
+(test-perm #(1 2 3 4 5) 4)
+(test-perm #(1 2 3 4 5) 5)
+(test-perm #(1 2 3 4 5) 5)
+
+(test-perm '() 0)
+(test-perm '() 1)
+(test-perm '(1) 0)
+(test-perm '(1) 1)
+(test-perm '(1) 2)
+(test-perm '(1 2) 0)
+(test-perm '(1 2) 1)
+(test-perm '(1 2) 2)
+(test-perm '(1 2) 3)
+(test-perm '(1 2 3) 0)
+(test-perm '(1 2 3) 1)
+(test-perm '(1 2 3) 2)
+(test-perm '(1 2 3) 3)
+(test-perm '(1 2 3) 4)
+(test-perm '(1 2 3 4) 0)
+(test-perm '(1 2 3 4) 1)
+(test-perm '(1 2 3 4) 2)
+(test-perm '(1 2 3 4) 3)
+(test-perm '(1 2 3 4) 4)
+(test-perm '(1 2 3 4) 5)
+(test-perm '(1 2 3 4 5) 0)
+(test-perm '(1 2 3 4 5) 1)
+(test-perm '(1 2 3 4 5) 2)
+(test-perm '(1 2 3 4 5) 3)
+(test-perm '(1 2 3 4 5) 4)
+(test-perm '(1 2 3 4 5) 5)
+(test-perm '(1 2 3 4 5) 5)
+
+(test-perm "" 0)
+(test-perm "" 1)
+(test-perm "1" 0)
+(test-perm "1" 1)
+(test-perm "1" 2)
+(test-perm "12" 0)
+(test-perm "12" 1)
+(test-perm "12" 2)
+(test-perm "12" 3)
+(test-perm "123" 0)
+(test-perm "123" 1)
+(test-perm "123" 2)
+(test-perm "123" 3)
+(test-perm "123" 4)
+(test-perm "1234" 0)
+(test-perm "1234" 1)
+(test-perm "1234" 2)
+(test-perm "1234" 3)
+(test-perm "1234" 4)
+(test-perm "1234" 5)
+(test-perm "12345" 0)
+(test-perm "12345" 1)
+(test-perm "12345" 2)
+(test-perm "12345" 3)
+(test-perm "12345" 4)
+(test-perm "12345" 5)
+(test-perm "12345" 5)
+
+(mtest
+ (perm #() -1) :error
+ (perm #(1) -1) :error
+ (perm () -1) :error
+ (perm '(1) -1) :error
+ (perm "" -1) :error
+ (perm "a" -1) :error)
+
+(test-rperm #() 0)
+(test-rperm #() 1)
+(test-rperm #(1) 0)
+(test-rperm #(1) 1)
+(test-rperm #(1) 2)
+(test-rperm #(1 2) 0)
+(test-rperm #(1 2) 1)
+(test-rperm #(1 2) 2)
+(test-rperm #(1 2) 3)
+(test-rperm #(1 2 3) 0)
+(test-rperm #(1 2 3) 1)
+(test-rperm #(1 2 3) 2)
+(test-rperm #(1 2 3) 3)
+(test-rperm #(1 2 3) 4)
+(test-rperm #(1 2 3 4) 0)
+(test-rperm #(1 2 3 4) 1)
+(test-rperm #(1 2 3 4) 2)
+(test-rperm #(1 2 3 4) 3)
+(test-rperm #(1 2 3 4) 4)
+(test-rperm #(1 2 3 4) 5)
+(test-rperm #(1 2 3 4 5) 0)
+(test-rperm #(1 2 3 4 5) 1)
+(test-rperm #(1 2 3 4 5) 2)
+(test-rperm #(1 2 3 4 5) 3)
+(test-rperm #(1 2 3 4 5) 4)
+(test-rperm #(1 2 3 4 5) 5)
+(test-rperm #(1 2 3 4 5) 5)
+
+(test-rperm '() 0)
+(test-rperm '() 1)
+(test-rperm '(1) 0)
+(test-rperm '(1) 1)
+(test-rperm '(1) 2)
+(test-rperm '(1 2) 0)
+(test-rperm '(1 2) 1)
+(test-rperm '(1 2) 2)
+(test-rperm '(1 2) 3)
+(test-rperm '(1 2 3) 0)
+(test-rperm '(1 2 3) 1)
+(test-rperm '(1 2 3) 2)
+(test-rperm '(1 2 3) 3)
+(test-rperm '(1 2 3) 4)
+(test-rperm '(1 2 3 4) 0)
+(test-rperm '(1 2 3 4) 1)
+(test-rperm '(1 2 3 4) 2)
+(test-rperm '(1 2 3 4) 3)
+(test-rperm '(1 2 3 4) 4)
+(test-rperm '(1 2 3 4) 5)
+(test-rperm '(1 2 3 4 5) 0)
+(test-rperm '(1 2 3 4 5) 1)
+(test-rperm '(1 2 3 4 5) 2)
+(test-rperm '(1 2 3 4 5) 3)
+(test-rperm '(1 2 3 4 5) 4)
+(test-rperm '(1 2 3 4 5) 5)
+(test-rperm '(1 2 3 4 5) 5)
+
+(test-rperm "" 0)
+(test-rperm "" 1)
+(test-rperm "1" 0)
+(test-rperm "1" 1)
+(test-rperm "1" 2)
+(test-rperm "12" 0)
+(test-rperm "12" 1)
+(test-rperm "12" 2)
+(test-rperm "12" 3)
+(test-rperm "123" 0)
+(test-rperm "123" 1)
+(test-rperm "123" 2)
+(test-rperm "123" 3)
+(test-rperm "123" 4)
+(test-rperm "1234" 0)
+(test-rperm "1234" 1)
+(test-rperm "1234" 2)
+(test-rperm "1234" 3)
+(test-rperm "1234" 4)
+(test-rperm "1234" 5)
+(test-rperm "12345" 0)
+(test-rperm "12345" 1)
+(test-rperm "12345" 2)
+(test-rperm "12345" 3)
+(test-rperm "12345" 4)
+(test-rperm "12345" 5)
+(test-rperm "12345" 5)
+
+(mtest
+ (rperm #() -1) :error
+ (rperm #(1) -1) :error
+ (rperm () -1) :error
+ (rperm '(1) -1) :error
+ (rperm "" -1) :error
+ (rperm "a" -1) :error)