(require 'stdlib) (require 'rep.test.framework) (puts "list elements") (let ((xs '(a b c d e))) (assert (= 'a (first xs))) (assert (= '(b c d e) (rest xs))) (assert (= 'b (second xs))) (assert (= 'c (third xs))) (assert (= 'd (fourth xs)))) (puts "inc/dec") (let ((x 0)) (inc x) (assert (= x 1)) (dec x) (assert (= x 0))) (puts "push/pop") (let ((xs '())) (push 1 xs) (push 2 xs) (assert (= '(2 1) xs)) (assert (= 2 (pop xs))) (assert (= 1 (pop xs))) (assert (= nil (pop xs)))) (puts "replace") (let ((xs '(0 1 2 3 4))) (replace xs 2 'foo) (assert (= '(0 1 foo 3 4) xs))) (puts "factorial") (assert (= 265252859812191058636308480000000 (factorial 30))) (puts "fibonacci") (assert (= 354224848179261915075 (fibonacci 100))) (puts "map") (assert (= '(1 1 2 3 5 8 13 21 34 55) (map fibonacci (make-range 1 10)))) (define (square i) (* i i)) (assert (= '(1 4 9 16 25 36 49 64 81 100) (map square (make-range 1 10)))) (assert (= '(1 8 27 64 125 216 343 512 729 1000) (map (lambda (x) (* x x x)) (make-range 1 10)))) (assert (= '(1 2 3) (map car '((1 a) (2 b) (3 c))))) (assert (= '(3 4 2 5 6) (map abs '(3 -4 2 -5 -6)))) (assert (= '((A . 1) (B . 2) (C . 3)) (map cons '(A B C) '(1 2 3)))) (puts "zip/unzip") (assert (= '((1 4) (2 5) (3 6)) (zip '(1 2 3) '(4 5 6)))) (assert (= '(1 3 5) (unzip1 '((1 2) (3 4) (5 6))))) (assert (= '((1 3 5) (2 4 6)) (unzip2 '((1 2) (3 4) (5 6))))) (assert (= '((1 2 3) (4 5 6) (7 8 9)) (unzip3 '((1 4 7) (2 5 8) (3 6 9))))) (assert (= '((1 3 5 7) (2 4 6 8) (a c e g) (b d f h)) (unzip4 '((1 2 a b) (3 4 c d) (5 6 e f) (7 8 g h))))) (assert (= '((a f k p u) (b g l q v) (c h m r w) (d i n s x) (e j o t y)) (unzip5 '((a b c d e) (f g h i j) (k l m n o) (p q r s t) (u v w x y))))) (puts "reduce") (assert (= 15 (reduce + 0 '(1 2 3 4 5)))) (puts "for") (assert (= '(4 3 2 1 0) (let ((xs '())) (for i 0 4 (push i xs)) xs))) (puts "dotimes") (assert (= '(4 3 2 1 0) (let ((xs '())) (dotimes i 5 (push i xs)) xs))) ;; FIXME finish these tests (puts "time - no test") ;; logic: ;; temporarily redirect standard-output to our own string-output-stream, ;; assert that the result is an inexact number, > 0. ;;(let ((old-standard-output standard-output) ;; (standard-output (make-string-output-stream)) ;; result) ;; (time (fac 1000)) ;; (setq result (string->number (get-output-stream-string standard-output))) ;; (setq standard-output old-standard-output) ;; (puts result)) (puts "with-open-file - no test") ;; assert that the contents of a well-known file are read correctly? (puts "dolist - no test") ;; same as map, mapcar, etc. (puts "multiple-value-bind") (define (f) (values 1 2)) (multiple-value-bind (a b) (f) (assert (= a 1)) (assert (= b 2)))