]> git.rkrishnan.org Git - sicp.git/blobdiff - src/sicp/ex1_31.clj
solution to 4.31
[sicp.git] / src / sicp / ex1_31.clj
index a1c8dd76b7421cde87e0c8bc588888871e0dc0c2..6878fde058ea1b4a27ebf27880c38caa73a4c8a1 100644 (file)
   (prod identity 1 inc n))
 
 (deftest test-factorial-of-6
-  (is (factorial 6) 720))
+  (is (= (factorial 6)
+        (reduce * (range 1 7)))))
 
 (deftest test-factorial-of-10
-  (is (factorial 10) 3628800))
+  (is (= (factorial 10)
+        (reduce * (range 1 11)))))
 
 (defn prod-pi [a b]
   (prod #(/ (* % (+ % 2)) (square (+ % 1.0))) a #(+ % 2) b))
 
 (deftest test-pi-2-digits-accuracy
-  (is (> (Math/abs (- 3.14159 (* 4 (prod-pi 2 1000)))) 0.001) true))
+  (is (= (> (Math/abs (- 3.14159 (* 4 (prod-pi 2 1000)))) 0.001) true)))
 
 (defn iter-prod [term a next b result]
   (if (> a b)
@@ -40,4 +42,5 @@
   (iter-prod term a next b 1))
 
 (deftest test-iprod-for-prod-of-1-to-10
-  (is (iprod identity 1 inc 10) (prod identity 1 inc 10)))
+  (is (= (iprod identity 1 inc 10)
+        (prod identity 1 inc 10))))