tisp

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

commit 00591ce43be8d719136c93dcab847ed25a86d2b8
parent a3bdeaf28b0527317ce3dbf9ce5b8c95fa98782d
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 10 Oct 2019 00:29:52 -0700

Test standard list functions

Diffstat:
test.c | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 57 insertions(+), 5 deletions(-)

diff --git a/test.c b/test.c @@ -163,7 +163,7 @@ char *tests[][2] = { { "(= '(1 2 3) '(1 2))", "()" }, { "(= '(1 2 3) '(1))", "()" }, { "(= '((1 2) 3 4) '((1 2) 3 4))", "t" }, - { "(= '((1 b) 3 4) '((1 2) 3 4))", "()" }, + { "(= '((1 b) 3 4) '((1 2) 3 4))", "()" }, { "define", NULL }, { "(define foo 4)", "" }, @@ -222,21 +222,73 @@ char *tests[][2] = { { "(nor () t)", "()" }, { "(nor t t)", "()" }, + { "list", NULL }, + { "(list 1 2 3)", "(1 2 3)" }, + { "(list (* 2 2) (+ 2 3))", "(4 5)" }, + { "(list 'a 'b 'c 'd 'e 'f)", "(a b c d e f)" }, + { "(list \"foo\")", "(\"foo\")" }, + { "(list)", "()" }, + { "(list 1/2 2/8 . 1/8)", "(1/2 1/4 . 1/8)" }, + { "(list* .5 .25 .125)", "(0.5 0.25 . 0.125)" }, + { "(list* 1 2 3 4 5 6)", "(1 2 3 4 5 . 6)" }, + { "(list* (sqr 3) (cube 4))", "(9 . 64)" }, + { "(list* 5/4)", "5/4" }, + { "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" }, + { "length", NULL }, + { "(length '(1 2 3))", "3" }, + { "(length (list .3 -3/2 12 5))", "4" }, + { "(length '(a b))", "2" }, + { "(length (list list))", "1" }, + { "(length ())", "0" }, + { "(length nil)", "0" }, + + { "nth", NULL }, + { "(nth 1 '(1 2 3))", "2" }, + { "(nth 2 (list 3 5/2 .332 -2))", "0.332" }, + { "(nth 0 '(a b c))", "a" }, + { "(nth 3 (list 'foo 'bar 'zar 'baz))", "baz" }, + + { "apply", NULL }, + { "(apply list '(1 2 3))", "(1 2 3)" }, + { "(apply + '(2 90))", "92" }, + { "(apply list '(a b c d e))", "(a b c d e)" }, + + { "map", NULL }, + { "(map car '((1 a) (2 b) (3 c)))", "(1 2 3)" }, + { "(map cdr '((1 a) (2 b) (3 c)))", "((a) (b) (c))" }, + { "(map (lambda (x) (car (cdr x))) '((1 a) (2 b) (3 c)))", "(a b c)" }, + { "(map cadr '((1/2 .5) (\"conky\" .25) ('bubbles .125)))", "(0.5 0.25 0.125)" }, + { "(map inc (list 2 4 8 (^ 2 4)))", "(3 5 9 17)" }, + + { "reverse", NULL }, + { "(reverse '(1 2 3 4 5))", "(5 4 3 2 1)" }, + { "(reverse (list -20 5/2 .398))", "(0.398 5/2 -20)" }, + { "(reverse '(a b))", "(b a)" }, + { "(reverse (list \"foo\" \"bar\" \"baz\"))", "(\"baz\" \"bar\" \"foo\")" }, + { "(reverse (cons 1/2 nil))", "(1/2)" }, + { "(reverse ())", "()" }, { "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)))", "()" }, + { "zip", NULL }, + { "(zip '(1 2 3 4) '(a b c d))", + "((1 . a) (2 . b) (3 . c) (4 . d))" }, + { "(zip (list 'ricky 'lahey) (list \"julian\" \"randy\"))", + "((ricky . \"julian\") (lahey . \"randy\"))" }, + + { "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)))", "()" }, + { "(assoc 4/3 (list (list 1 pi) (list 4/3 1/2 3) (list 2 3)))", "(4/3 1/2 3)" }, { "member?", NULL }, { "(member? 'foo '(foo bar baz))", "t" },