(defn compose [f g]
(fn [x] (f (g x))))
+
+(deftest test-compose-square-of-inc-of-6
+ (is (= ((compose square inc) 6)
+ 49)))
+
+(deftest test-compose-square-of-square-of-2
+ (is (= ((compose square square) 2)
+ 16)))
+
(comment
-((compose square inc) 6)
-;;=> 49
-((compose square square) 2)
-;;=> 16
+;; from repl do
+ (use 'sicp.ex1_42 :reload)
+ (run-tests 'sicp.ex1_42)
)
\ No newline at end of file
(defn repeated [f n]
(repeated-1 f (compose f f) (- n 1)))
+(deftest test-repeated-square-twotimes-of-5
+ (is (= ((repeated square 2) 5)
+ 625)))
+
+(deftest test-repeated-square-twotimes-of-2
+ (is (= ((repeated square 2) 2)
+ 16)))