summaryrefslogtreecommitdiffstats
path: root/tests/015/comb.tl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/015/comb.tl')
-rw-r--r--tests/015/comb.tl116
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/015/comb.tl b/tests/015/comb.tl
new file mode 100644
index 00000000..c60b8f2a
--- /dev/null
+++ b/tests/015/comb.tl
@@ -0,0 +1,116 @@
+(load "../common")
+
+(defun normtype (obj)
+ (etypecase obj
+ (null 'list)
+ (cons 'list)
+ (lit 'string)
+ (str 'string)
+ (vec 'vec)))
+
+(defun test-comb (s k)
+ (let ((out (comb s k))
+ (nCk (n-choose-k (len s) k)))
+ (if (> k (len s))
+ (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)))))
+
+(test-comb #() 0)
+(test-comb #() 1)
+(test-comb #(1) 0)
+(test-comb #(1) 1)
+(test-comb #(1) 2)
+(test-comb #(1 2) 0)
+(test-comb #(1 2) 1)
+(test-comb #(1 2) 2)
+(test-comb #(1 2) 3)
+(test-comb #(1 2 3) 0)
+(test-comb #(1 2 3) 1)
+(test-comb #(1 2 3) 2)
+(test-comb #(1 2 3) 3)
+(test-comb #(1 2 3) 4)
+(test-comb #(1 2 3 4) 0)
+(test-comb #(1 2 3 4) 1)
+(test-comb #(1 2 3 4) 2)
+(test-comb #(1 2 3 4) 3)
+(test-comb #(1 2 3 4) 4)
+(test-comb #(1 2 3 4) 5)
+(test-comb #(1 2 3 4 5) 0)
+(test-comb #(1 2 3 4 5) 1)
+(test-comb #(1 2 3 4 5) 2)
+(test-comb #(1 2 3 4 5) 3)
+(test-comb #(1 2 3 4 5) 4)
+(test-comb #(1 2 3 4 5) 5)
+(test-comb #(1 2 3 4 5) 5)
+
+(test-comb '() 0)
+(test-comb '() 1)
+(test-comb '(1) 0)
+(test-comb '(1) 1)
+(test-comb '(1) 2)
+(test-comb '(1 2) 0)
+(test-comb '(1 2) 1)
+(test-comb '(1 2) 2)
+(test-comb '(1 2) 3)
+(test-comb '(1 2 3) 0)
+(test-comb '(1 2 3) 1)
+(test-comb '(1 2 3) 2)
+(test-comb '(1 2 3) 3)
+(test-comb '(1 2 3) 4)
+(test-comb '(1 2 3 4) 0)
+(test-comb '(1 2 3 4) 1)
+(test-comb '(1 2 3 4) 2)
+(test-comb '(1 2 3 4) 3)
+(test-comb '(1 2 3 4) 4)
+(test-comb '(1 2 3 4) 5)
+(test-comb '(1 2 3 4 5) 0)
+(test-comb '(1 2 3 4 5) 1)
+(test-comb '(1 2 3 4 5) 2)
+(test-comb '(1 2 3 4 5) 3)
+(test-comb '(1 2 3 4 5) 4)
+(test-comb '(1 2 3 4 5) 5)
+(test-comb '(1 2 3 4 5) 5)
+
+(test-comb "" 0)
+(test-comb "" 1)
+(test-comb "1" 0)
+(test-comb "1" 1)
+(test-comb "1" 2)
+(test-comb "12" 0)
+(test-comb "12" 1)
+(test-comb "12" 2)
+(test-comb "12" 3)
+(test-comb "123" 0)
+(test-comb "123" 1)
+(test-comb "123" 2)
+(test-comb "123" 3)
+(test-comb "123" 4)
+(test-comb "1234" 0)
+(test-comb "1234" 1)
+(test-comb "1234" 2)
+(test-comb "1234" 3)
+(test-comb "1234" 4)
+(test-comb "1234" 5)
+(test-comb "12345" 0)
+(test-comb "12345" 1)
+(test-comb "12345" 2)
+(test-comb "12345" 3)
+(test-comb "12345" 4)
+(test-comb "12345" 5)
+(test-comb "12345" 5)
+
+(mtest
+ (comb #() -1) :error
+ (comb #(1) -1) :error
+ (comb () -1) :error
+ (comb '(1) -1) :error
+ (comb "" -1) :error
+ (comb "a" -1) :error)