commit 28028036161ef3990b5d14d9f79db1ee6a143cca
parent 9f66f5ff824b3e976ebe9bfd86d2e7266ce19cfd
Author: Ed van Bruggen <edvb@uw.edu>
Date: Thu, 8 Aug 2019 01:46:41 -0700
Unit tests for list functions
Diffstat:
test.c | | | 95 | ++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- |
1 file changed, 56 insertions(+), 39 deletions(-)
diff --git a/test.c b/test.c
@@ -187,6 +187,62 @@ char *tests[][2] = {
{ "((lambda (a b) (+ a b)) 2 2)", "4" },
{ "((lambda () 5))", "5" },
+ { "control", NULL },
+ { "(if t 1 2)", "1" },
+ { "(if () 1 2)", "2" },
+ { "(if (integer? 3) t ())", "t" },
+ { "(if (ratio? car) (cons 1 2) (car '(1 2)))", "1" },
+ { "(when t 'foo)", "foo" },
+ { "(when () 'b ar)", "" },
+ { "(when (= 1 1) 4)", "4" },
+ { "(unless t 'foo)", "" },
+ { "(unless () 'bar)", "bar" },
+ { "(unless 3 4)", "" },
+ { "(unless (< 5 4) 7)", "7" },
+
+ { "logic", NULL },
+ { "(not ())", "t" },
+ { "(not t)", "()" },
+ { "(and () ())", "()" },
+ { "(and t ())", "()" },
+ { "(and () t)", "()" },
+ { "(and t t)", "t" },
+ { "(nand () ())", "t" },
+ { "(nand t ())", "t" },
+ { "(nand () t)", "t" },
+ { "(nand t t)", "()" },
+ { "(or () ())", "()" },
+ { "(or t ())", "t" },
+ { "(or () t)", "t" },
+ { "(or t t)", "t" },
+ { "(nor () ())", "t" },
+ { "(nor t ())", "()" },
+ { "(nor () t)", "()" },
+ { "(nor t t)", "()" },
+
+ { "last", NULL },
+ { "(last '(1 2 3))", "3" },
+ { "(last (list 4 5))", "5" },
+ { "(last '(a b c d e f))", "f" },
+ { "(last (cons 1 (cons 2 ())))", "2" },
+
+ { "append", NULL },
+ { "(append '(1 2 3) '(4 5 6))", "(1 2 3 4 5 6)" },
+ { "(append (list (+ 1 2) 4) '(a b c))", "(3 4 a b c)" },
+
+ { "assoc", NULL },
+ { "(assoc 'baz '((foo 3) (bar 8) (baz 14)))", "(baz 14)" },
+ { "(assoc 'a '((a b) (3 2.1) (3.2 4/3) (3.2 3.2)))", "(a b)" },
+ { "(assoc 3 '((1 b)))", "()" },
+
+ { "member?", NULL },
+ { "(member? 'foo '(foo bar baz))", "t" },
+ { "(member? 'bar '(foo bar baz))", "t" },
+ { "(member? 4 '(12 38 4 8))", "t" },
+ { "(member? 3.2 '(4/3 2 8 2 3.14 3.2))", "t" },
+ { "(member? \"quux\" (list 4.2 3 'quux))", "()" },
+ { "(member? 'qux '(foo bar baz))", "()" },
+
{ "numerator", NULL },
{ "(numerator 3/2)", "3" },
{ "(numerator 1/2)", "1" },
@@ -284,45 +340,6 @@ char *tests[][2] = {
{ "(>= 39 39)", "t" },
{ "(>= -32 -30)", "()" },
- { "control", NULL },
- { "(if t 1 2)", "1" },
- { "(if () 1 2)", "2" },
- { "(if (integer? 3) t ())", "t" },
- { "(if (ratio? car) (cons 1 2) (car '(1 2)))", "1" },
- { "(when t 'foo)", "foo" },
- { "(when () 'b ar)", "" },
- { "(when (= 1 1) 4)", "4" },
- { "(unless t 'foo)", "" },
- { "(unless () 'bar)", "bar" },
- { "(unless 3 4)", "" },
- { "(unless (< 5 4) 7)", "7" },
-
- { "logic", NULL },
- { "(not ())", "t" },
- { "(not t)", "()" },
- { "(and () ())", "()" },
- { "(and t ())", "()" },
- { "(and () t)", "()" },
- { "(and t t)", "t" },
- { "(nand () ())", "t" },
- { "(nand t ())", "t" },
- { "(nand () t)", "t" },
- { "(nand t t)", "()" },
- { "(or () ())", "()" },
- { "(or t ())", "t" },
- { "(or () t)", "t" },
- { "(or t t)", "t" },
- { "(nor () ())", "t" },
- { "(nor t ())", "()" },
- { "(nor () t)", "()" },
- { "(nor t t)", "()" },
-
- { "last", NULL },
- { "(last '(1 2 3))", "3" },
- { "(last (list 4 5))", "5" },
- { "(last '(a b c d e f))", "f" },
- { "(last (cons 1 (cons 2 ())))", "2" },
-
{ "abs", NULL },
{ "(abs 4)", "4" },
{ "(abs -3/5)", "3/5" },