tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 1288fd4ee1199f27f7e5cb8789afdbb330c68d84
parent 71a51439b0f4ad759c6c8312fb3ad5554e1a7a08
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat,  1 Jun 2019 18:53:03 -0700

Add tests for standard tisp library functions

Diffstat:
test.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 68 insertions(+), 6 deletions(-)

diff --git a/test.c b/test.c @@ -10,9 +10,6 @@ #define LEN(X) (sizeof(X) / sizeof((X)[0])) - - -/* TODO mark and show which lines error-ed */ char *tests[][2] = { { "self", NULL }, @@ -122,10 +119,10 @@ char *tests[][2] = { { "(cond)", "()" }, { "(cond (t 1))", "1" }, { "(cond ((= 1 1) 1) ((= 1 2) 2) (t 3))", "1" }, - { "(cond ((= 1 2) 1) ((= 1 2) 2) (t (+ 1 2)))", "3" }, - { "(cond ((= 1 2) 1) ((= 1 1) 2) (t 3))", "2" }, + { "(cond ((= 1 2) 1) ((= 1 2) 2) (else (+ 1 2)))", "3" }, + { "(cond ((= 1 2) 1) ((= 1 1) 2) (else 3))", "2" }, { "(cond ((= 1 2) 1) ((= 1 3) 2))", "()" }, - { "(cond ((= 1 2) 1) (\"foo\" 2) (t 3))", "2" }, + { "(cond ((= 1 2) 1) (\"foo\" 2) (else 3))", "2" }, { "(cond (() (+ 1 2)))", "()" }, { "eq", NULL }, @@ -280,6 +277,71 @@ 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" }, + { "(abs 0.0)", "0.0" }, + + { "sgn", NULL }, + { "(sgn 239)", "1" }, + { "(sgn -3)", "-1" }, + { "(sgn 5/4)", "1" }, + { "(sgn -1/7)", "-1" }, + { "(sgn 3.17)", "1" }, + { "(sgn -.457)", "-1" }, + { "(sgn 0)", "0" }, + { "(sgn 0.0)", "0" }, + + { "max/min", NULL }, + { "(max 9346 13297)", "13297" }, + { "(max -3 8)", "8" }, + { "(max 3/2 1/2)", "3/2" }, + { "(max 0 -.5)", "0" }, + { "(min 4 48)", "4" }, + { "(min -80 -148)", "-148" }, + { "(min 7/2 -3)", "-3" }, + { "(min 1/2 1/3)", "1/3" }, + { "(min .05 .06)", "0.05" }, + { NULL, NULL }, };