From ec6c3e5d61f64e13ceaf6ad3c505fe97df193df3 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Mon, 7 Jun 2010 17:38:35 +0530
Subject: [PATCH] solution to 2.2 with tests

---
 src/sicp/ex2_2.clj | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 src/sicp/ex2_2.clj

diff --git a/src/sicp/ex2_2.clj b/src/sicp/ex2_2.clj
new file mode 100644
index 0000000..37d61c8
--- /dev/null
+++ b/src/sicp/ex2_2.clj
@@ -0,0 +1,37 @@
+(ns sicp.ex2_2
+  (:use [sicp utils]
+	[clojure.test]))
+
+(defn make-segment [x y]
+  (list x y))
+
+(defn start-segment [seg]
+  (first seg))
+
+(defn end-segment [seg]
+  (first (rest seg)))
+
+(defn make-point [x y]
+  (list x y))
+
+(defn x-point [p]
+  (first p))
+
+(defn y-point [p]
+  (first (rest p)))
+
+(defn midpoint-segment [seg]
+  (let [x1 (x-point (start-segment seg))
+	y1 (y-point (start-segment seg))
+	x2 (x-point (end-segment seg))
+	y2 (y-point (end-segment seg))]
+    (make-point (average x1 x2)
+		(average y1 y2))))
+
+
+(deftest test-mid-point-1-1-3-3
+  (let [m (midpoint-segment (make-segment  (make-point 1 1)
+					   (make-point 3 3)))]
+    (are [x y] [approx-equal x y]
+	 (x-point m) 2.0
+	 (y-point m) 2.0)))
\ No newline at end of file
-- 
2.45.2