Skip to content

Commit

Permalink
add test function
Browse files Browse the repository at this point in the history
  • Loading branch information
anttih committed Feb 26, 2012
1 parent f3d561e commit 107756c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions repl.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
(defprimitive < <)
(defprimitive = =)
(defprimitive eq? eq?)
(defprimitive equal? equal?)
(defprimitive not not)
(defprimitive list list)
(defprimitive null? null?)
(defprimitive first car)
Expand Down
21 changes: 14 additions & 7 deletions test/test.lol
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

(def (test name expected thunk)
(let (res (thunk))
(if (not (equal? res expected))
(print "[FAIL] " name " expected " expected " but got " res)
(print "[PASS] " name))))

(def (map f l)
(if (null? l)
(list)
Expand All @@ -16,16 +22,13 @@
1
(* n (fact (- n 1)))))

(print (map (compose square fact) (list 3 4 5)))

(def my-hash {:key "first value" :other "second value"})
(test "compose and map ints" (list 36 576 14400)
(fn () (map (compose square fact) (list 3 4 5))))

(print (hash-ref my-hash :key))
(print (hash-ref my-hash :other))

(def my-vector [1 2 3 4])
(test "hash-ref" "value" (fn () (hash-ref {:key "value"} :key)))

(print (nth my-vector 2))
(test "vector nth" 3 (fn () (nth [1 2 3 4] 2)))

(def name "success")

Expand All @@ -40,6 +43,10 @@
(print "ok: Non-local return")
(cc 1)))

;; stupid call/cc test
(test "simple arithmetic" 2 (fn () (+ 1 1)))
(test "This should pass" 1 (fn () 1))

(print "Two times:")
(print (call/cc (fn (c) (set! again c) "- first")))
(again "- second")

0 comments on commit 107756c

Please sign in to comment.