]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex1_43.clj
added a few tests
[sicp.git] / src / sicp / ex1_43.clj
1 (ns sicp.ex1_43
2   (:use [clojure.contrib test-is]
3         [sicp utils]
4         [sicp ch1_3]
5         [sicp ex1_42]))
6
7 (defn repeated-1 [f1 f2 m]
8   (cond (= m 0) f1
9         (= m 1) f2
10         :else (repeated-1 f1 (compose f2 f1) (- m 1))))
11
12 (defn repeated [f n]
13   (repeated-1 f (compose f f) (- n 1)))
14
15 (deftest test-repeated-square-twotimes-of-5
16   (is (= ((repeated square 2) 5)
17          625)))
18
19 (deftest test-repeated-square-twotimes-of-2
20   (is (= ((repeated square 2) 2)
21          16)))