2 (:use [clojure.contrib test-is]
8 (* a (product (+ a 1) b))))
10 (defn prod [term a next b]
14 (prod term (next a) next b))))
17 ;; fact (n) = n * factorial (n - 1)
20 (prod identity 1 inc n))
22 (deftest test-factorial-of-6
24 (reduce * (range 1 7)))))
26 (deftest test-factorial-of-10
28 (reduce * (range 1 11)))))
31 (prod #(/ (* % (+ % 2)) (square (+ % 1.0))) a #(+ % 2) b))
33 (deftest test-pi-2-digits-accuracy
34 (is (= (> (Math/abs (- 3.14159 (* 4 (prod-pi 2 1000)))) 0.001) true)))
36 (defn iter-prod [term a next b result]
39 (iter-prod term (next a) next b (* a result))))
41 (defn iprod [term a next b]
42 (iter-prod term a next b 1))
44 (deftest test-iprod-for-prod-of-1-to-10
45 (is (= (iprod identity 1 inc 10)
46 (prod identity 1 inc 10))))