From 5de2388c9f6082ef9bd0bd18466cff5c9d81c32a Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Sun, 30 May 2010 08:49:56 +0530
Subject: [PATCH] added test cases and fixed a bug.

---
 src/sicp/ex1_46.clj | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/sicp/ex1_46.clj b/src/sicp/ex1_46.clj
index 0cf3d0c..3b21dbd 100644
--- a/src/sicp/ex1_46.clj
+++ b/src/sicp/ex1_46.clj
@@ -13,7 +13,7 @@
   (let [initial-guess 1.0]
     ((iterative-improve
       (fn [old new] (< (Math/abs (- old new)) 0.00001))
-      (fn [guess] (average guess x)))
+      (fn [guess] (average guess (/ x guess))))
      initial-guess)))
 
 (defn fixed-point [f initial-guess]
@@ -21,13 +21,28 @@
     (fn [old new] (< (Math/abs (- old new)) 0.00001))
     f) initial-guess))
 
+(deftest test-sqrt-4
+  (is #(< (Math/abs (- (sqrt 4) (Math/sqrt 4))) 0.00001)))
+
+(deftest test-sqrt-10
+  (is #(< (Math/abs (- (sqrt 10) (Math/sqrt 10))) 0.00001)))
+
+(deftest test-fixed-point-cos
+  (is (fn [_] (< (Math/abs (- (fixed-point #(Math/cos %) 1.0)
+			      0.7390822))
+		 0.00001))))
+
+(deftest test-fixed-point-cos-plus-sin
+  (is (fn [_] (< (Math/abs (- (fixed-point #(+ (Math/cos %) (Math/sin %)) 1.0)
+			      1.258731))
+		 0.00001))))
+
+
+
 (comment
-(sqrt 4)
-;;=> 3.9999942779541016
-user> (sqrt (* 2 2))
-;;=> 3.9999942779541016
 user> (fixed-point #(Math/cos %) 1.0)
 ;;=> 0.7390822985224024
 user> (fixed-point #(+ (Math/cos %) (Math/sin %)) 1.0)
 ;;=> 1.2587315962971173  
-)
\ No newline at end of file
+)
+
-- 
2.45.2