aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_contrib/complex_numbers.clj
diff options
context:
space:
mode:
authorKonrad Hinsen <konrad.hinsen@laposte.net>2009-03-23 11:49:31 +0000
committerKonrad Hinsen <konrad.hinsen@laposte.net>2009-03-23 11:49:31 +0000
commit611ec68f65624f34b05739c75a722eb8ac7131ef (patch)
tree8fdd96ae87923dbb346e9fd2cf8e5f8a1caae39d /src/clojure/contrib/test_contrib/complex_numbers.clj
parentabd6be55e42eb77dc2bf49a7c9f6d67584de77ee (diff)
complex-numbers: abs, conjugate, sqrt
Diffstat (limited to 'src/clojure/contrib/test_contrib/complex_numbers.clj')
-rw-r--r--src/clojure/contrib/test_contrib/complex_numbers.clj26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/clojure/contrib/test_contrib/complex_numbers.clj b/src/clojure/contrib/test_contrib/complex_numbers.clj
index ef874ba1..b8b03f49 100644
--- a/src/clojure/contrib/test_contrib/complex_numbers.clj
+++ b/src/clojure/contrib/test_contrib/complex_numbers.clj
@@ -1,7 +1,7 @@
;; Test routines for complex-numbers.clj
;; by Konrad Hinsen
-;; last updated March 19, 2009
+;; last updated March 23, 2009
;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use
;; and distribution terms for this software are covered by the Eclipse
@@ -12,13 +12,15 @@
;; remove this notice, or any other, from this software.
(ns clojure.contrib.test-contrib.complex-numbers
- (:refer-clojure :exclude [+ - * / =])
+ (:refer-clojure :exclude [+ - * / = < > <= >=])
(:use [clojure.contrib.test-is
:only (deftest is are run-tests)]
[clojure.contrib.generic.arithmetic
:only (+ - * /)]
[clojure.contrib.generic.comparison
- :only (=)]
+ :only (= < > <= >=)]
+ [clojure.contrib.generic.math-functions
+ :only (abs approx= conjugate sqr sqrt)]
[clojure.contrib.complex-numbers
:only (complex imaginary real imag)]))
@@ -269,3 +271,21 @@
(is (= (/ (imaginary 5) (imaginary -2)) -5/2))
(is (= (/ (imaginary -2) (imaginary 5)) -2/5))
(is (= (/ (imaginary 5) (imaginary 5)) 1)))
+
+(deftest complex-conjugate
+ (is (= (conjugate (complex 1 2)) (complex 1 -2)))
+ (is (= (conjugate (complex -3 -7)) (complex -3 7)))
+ (is (= (conjugate (imaginary -2)) (imaginary 2)))
+ (is (= (conjugate (imaginary 5)) (imaginary -5))))
+
+(deftest complex-abs
+ (doseq [c [(complex 1 2) (complex -3 -7) (imaginary -2) (imaginary 5)]]
+ (is (approx= (* c (conjugate c))
+ (sqr (abs c))
+ 1e-14))))
+
+(deftest complex-sqrt
+ (doseq [c [(complex 1 2) (complex -3 -7) (imaginary -2) (imaginary 5)]]
+ (let [r (sqrt c)]
+ (is (approx= c (sqr r) 1e-14))
+ (is (>= (real r) 0)))))