; test everything (defun test () (format t "~%~10TBEGIN TESTING~2%") (test-All-Len) (test-Range) (test-before) (test-split-if) (test-group) (test-mostn) (test-Match) (test-Match-Var) (format t "~%~10TDONE TESTING~2%") t ) ; some shorthands, so that you can just type, e.g., (tr) (defun tal () (test-All-Len)) (defun tr () (test-Range)) (defun tb () (test-before)) (defun ts () (test-split-if)) (defun tg () (test-group)) (defun tmn () (test-mostn)) (defun tmv () (test-Match-Var)) (defun tm () (test-Match)) ; use this to test everything and create Output.your ; then exit from clisp ; do a "diff Output.correct Output.your" ; (use "diff -i Output.correct Output.your" if you're using ; (setq *print-case* :downcase)) ; files should be identical, except first few heading lines. (defun td () (dribble "Output.your") (test) (dribble)) (defun test-All-Len () (format t "~%~20TTEST-All-Len~2%") (tester all-length nil ) (tester all-length '(a b c d e f) ) (tester all-length '((1 2 3) (4 5 6)) ) (tester all-length '(g () h (x y z ())) ) (tester all-length '(a (b c) (d (e f))) ) (tester all-length '(nil (()()) (a a (0 (((0))) ((())) (((nil a)))))) ) t ) (defun test-Range () (format t "~%~20TTEST-Range~2%") (tester range '(5) ) (tester range '(5 4 3 2 1) ) (tester range '(0 7 8 2 3 -1) ) (tester range '(8 8 8 8 8 8 8 8) ) (tester range '(8 8 8 8 8 8 8 9) ) (tester range '(6 6 5 4 3 2 1 1) ) t ) (defun test-before () (format t "~%~20TTEST-before~2%") (tester before 'a 'd '(a b c d e f)) (tester before 'd 'a '(a b c d e f)) (tester before 'a 'd '(1 2 3 d a d a)) (tester before 'a 'd '(c a d a b c d)) (tester before 'a 'd '()) (tester before 'a 'b '(1 2 3 a 0 b 4 5 6)) (tester before 'a 'b '(1 2 3 b a b a)) (tester before 'a 'b '(() b a c d (2 3))) (tester before 'a 'd '(a)) (tester before '(1 2) '(1 2 3) '((1 2) (1 2 3) (1 2) a)) t ) (defun test-split-if () (format t "~%~20TTEST-split-if~2%") (tester split-if #'null '()) (tester split-if #'listp '(1 2 3 () (a b) x (hi bye) z d)) (tester split-if #'atom '(a b c d e f () h i j () l () ())) (tester split-if #'(lambda (x) (not (= 0 (mod x 3)))) '(0 22 1 4 9 5 3 6 7 11 33 12 99)) (tester split-if #'(lambda (x) (> x 80)) '(55 66 22 100 99 89 78 83 72 69)) (tester split-if #'(lambda (x) (> (cadr x) 70)) '((bob 70) (lee 60) (sally 88) (mike 90) (lisa 100) (dan 99))) (tester split-if #'(lambda (x) (equal 'yellow (car x))) '((yellow sara jun)(blue dave fres) (green chris sen) (black lars sen)(red melissa sop) (yellow ken sen)(yellow holly sen))) (tester split-if #'(lambda (x) (> (length x) 3)) '((1 2 3)(33)(10 6 5 43 2) (0 a b)(hello how are you)()(a b c) (vanilla chocolate strawberry) (boo) (x y z u v w) (foo boo bar foo boo) (e) (i am done))) t ) (defun test-group() (format t "~%~20TTEST-group~2%") (tester group '() 1) (tester group '(a (a b) (c d) e f g) 3) (tester group '(1 2 3 4 5 5 8 9 a (c d) e f g) 8) (tester group '(a b c d e f g h) 1) (tester group '(((f g h))) 3) t ) (defun sqr (x) (* x x)) (defun add (x y) (+ x y)) (defun test-mostn() (format t "~%~20TTEST-mostn~2%") (tester mostn #'sqr '(1 8 4 8 3 9 8)) (tester mostn #'eval '((+ 1 2) (+ 3 4) (+ 4 3))) (tester mostn #'eval '((sqr 2) (sqr 4) (sqr 3))) t ) (defun test-Match () (format t "~%~20TTEST-Match~2%") (tester match '(think about that) '(think that about) ) (tester match '(think about that) '(think about that) ) (tester match '(think about that) nil ) (tester match nil '() ) (tester match nil '(nil) ) (tester match '(nil nil) '(nil) ) (tester match '(nil nil) '(nil nil) ) (tester match '(a a) '(a) ) (tester match '(a ?) '(a a) ) (tester match '(a nil ?) '(a nil nil) ) (tester match '(? ? ? ?) '(what time is it) ) (tester match '(? ? ? ? ?) '(what time is it now ah) ) (tester match '(? ? ? ? ?) '(what time is it) ) (tester match '(? color apple) '(color color apple nil) ) (tester match '(this table is round ?) '(this table is round or) ) (tester match '(this !) '(this table is round) ) (tester match '(this ! is round) '(this table is round) ) (tester match '(this table !) '(this this table is round) ) (tester match '(! table is round) '(this table is round or) ) (tester match '(! table is round) '(this table) ) (tester match '(this ! round) '(this table is round) ) (tester match '(is that fine ?) '(that fine too) ) (tester match '(!) '(no matter what) ) (tester match '(! !) '(no matter what) ) (tester match '(! ! !) '(no matter what) ) (tester match '(! ! ! !) '(no matter what) ) (tester match '(! big ! ?) '(a yellow big wooden bag) ) (tester match '(! big ! ?) '(a yellow big bag) ) (tester match '(! ! ? ! !) '(how are you today ah) ) (tester match '(! ! ! ! !) '(how are you today) ) (tester match '(! ? ? funny !) '(is it really funny or what) ) (tester match '(! ? ? funny !) '(is it really funny) ) (tester match '(? ? ! ? a) '(a a a a) ) (tester match '(? ? ! ? a !) '(a a a a a nil) ) (tester match '(! b ? b a b a ! ? !) '(b b a b a b a b a b a) ) (tester match '(! b ? a b a b ! ? !) '(b b a b a b a b a b) ) t ) (defun test-Match-Var () (format t "~%~20TTEST-Match-Var~2%") (tester match-var '(plus (? a) (? b)) '(plus 2 3) ) (tester eval 'a ) (tester eval 'b ) (tester match-var '((! u) a (? v)) '(b c a d) ) (tester eval 'u ) (tester eval 'v ) (tester match-var '((! u) (? v) c (! w)) '(b c a d) ) (tester match-var '(a (! u) a (? v) a (! w)) '(a a a a b a a) ) (tester eval 'u ) (tester eval 'v ) (tester eval 'w ) (tester match-var '(nil (! u) (! v) (? w) nil (! y) a a) '( nil nil a nil nil a a nil a a) ) (tester eval 'u ) (tester eval 'v ) (tester eval 'w ) (tester eval 'y ) (tester match-var '(nil (! u) (! v) (? w) nil (! y) a a) '( nil a nil nil a a nil a a) ) t ) ; low-level testing routine (defmacro tester (&rest x) (format t "testing: ~A~%" x) ; split into 2 so print value even if eval fails. (format t "value: ") (format t "~A~2%" (eval x)) t )