diff src/clojure/contrib/test_contrib/test_complex_numbers.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/test_contrib/test_complex_numbers.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,313 @@
     1.4 +;; Test routines for complex-numbers.clj
     1.5 +
     1.6 +;; by Konrad Hinsen
     1.7 +;; last updated April 2, 2009
     1.8 +
     1.9 +;; Copyright (c) Konrad Hinsen, 2008. All rights reserved.  The use
    1.10 +;; and distribution terms for this software are covered by the Eclipse
    1.11 +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
    1.12 +;; which can be found in the file epl-v10.html at the root of this
    1.13 +;; distribution.  By using this software in any fashion, you are
    1.14 +;; agreeing to be bound by the terms of this license.  You must not
    1.15 +;; remove this notice, or any other, from this software.
    1.16 +
    1.17 +(ns clojure.contrib.test-complex-numbers
    1.18 +  (:refer-clojure :exclude [+ - * / = < > <= >=])
    1.19 +  (:use [clojure.test
    1.20 +	 :only (deftest is are run-tests)]
    1.21 +	[clojure.contrib.generic.arithmetic
    1.22 +	 :only (+ - * /)]
    1.23 +	[clojure.contrib.generic.comparison
    1.24 +	 :only (= < > <= >=)]
    1.25 +	[clojure.contrib.generic.math-functions
    1.26 +	 :only (abs approx= conjugate exp sqr sqrt)]
    1.27 +	[clojure.contrib.complex-numbers
    1.28 +	 :only (complex imaginary real imag)]))
    1.29 +
    1.30 +(deftest complex-addition
    1.31 +  (is (= (+ (complex 1 2) (complex 1 2)) (complex 2 4)))
    1.32 +  (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5)))
    1.33 +  (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5)))
    1.34 +  (is (= (+ (complex 1 2) 3) (complex 4 2)))
    1.35 +  (is (= (+ 3 (complex 1 2)) (complex 4 2)))
    1.36 +  (is (= (+ (complex 1 2) -1) (imaginary 2)))
    1.37 +  (is (= (+ -1 (complex 1 2)) (imaginary 2)))
    1.38 +  (is (= (+ (complex 1 2) (imaginary -2)) 1))
    1.39 +  (is (= (+ (imaginary -2) (complex 1 2)) 1))
    1.40 +  (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7)))
    1.41 +  (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7)))
    1.42 +  (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5)))
    1.43 +  (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5)))
    1.44 +  (is (= (+ (complex -3 -7) (complex -3 -7)) (complex -6 -14)))
    1.45 +  (is (= (+ (complex -3 -7) 3) (imaginary -7)))
    1.46 +  (is (= (+ 3 (complex -3 -7)) (imaginary -7)))
    1.47 +  (is (= (+ (complex -3 -7) -1) (complex -4 -7)))
    1.48 +  (is (= (+ -1 (complex -3 -7)) (complex -4 -7)))
    1.49 +  (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9)))
    1.50 +  (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9)))
    1.51 +  (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2)))
    1.52 +  (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2)))
    1.53 +  (is (= (+ 3 (complex 1 2)) (complex 4 2)))
    1.54 +  (is (= (+ (complex 1 2) 3) (complex 4 2)))
    1.55 +  (is (= (+ 3 (complex -3 -7)) (imaginary -7)))
    1.56 +  (is (= (+ (complex -3 -7) 3) (imaginary -7)))
    1.57 +  (is (= (+ 3 (imaginary -2)) (complex 3 -2)))
    1.58 +  (is (= (+ (imaginary -2) 3) (complex 3 -2)))
    1.59 +  (is (= (+ 3 (imaginary 5)) (complex 3 5)))
    1.60 +  (is (= (+ (imaginary 5) 3) (complex 3 5)))
    1.61 +  (is (= (+ -1 (complex 1 2)) (imaginary 2)))
    1.62 +  (is (= (+ (complex 1 2) -1) (imaginary 2)))
    1.63 +  (is (= (+ -1 (complex -3 -7)) (complex -4 -7)))
    1.64 +  (is (= (+ (complex -3 -7) -1) (complex -4 -7)))
    1.65 +  (is (= (+ -1 (imaginary -2)) (complex -1 -2)))
    1.66 +  (is (= (+ (imaginary -2) -1) (complex -1 -2)))
    1.67 +  (is (= (+ -1 (imaginary 5)) (complex -1 5)))
    1.68 +  (is (= (+ (imaginary 5) -1) (complex -1 5)))
    1.69 +  (is (= (+ (imaginary -2) (complex 1 2)) 1))
    1.70 +  (is (= (+ (complex 1 2) (imaginary -2)) 1))
    1.71 +  (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9)))
    1.72 +  (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9)))
    1.73 +  (is (= (+ (imaginary -2) 3) (complex 3 -2)))
    1.74 +  (is (= (+ 3 (imaginary -2)) (complex 3 -2)))
    1.75 +  (is (= (+ (imaginary -2) -1) (complex -1 -2)))
    1.76 +  (is (= (+ -1 (imaginary -2)) (complex -1 -2)))
    1.77 +  (is (= (+ (imaginary -2) (imaginary -2)) (imaginary -4)))
    1.78 +  (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3)))
    1.79 +  (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3)))
    1.80 +  (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7)))
    1.81 +  (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7)))
    1.82 +  (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2)))
    1.83 +  (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2)))
    1.84 +  (is (= (+ (imaginary 5) 3) (complex 3 5)))
    1.85 +  (is (= (+ 3 (imaginary 5)) (complex 3 5)))
    1.86 +  (is (= (+ (imaginary 5) -1) (complex -1 5)))
    1.87 +  (is (= (+ -1 (imaginary 5)) (complex -1 5)))
    1.88 +  (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3)))
    1.89 +  (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3)))
    1.90 +  (is (= (+ (imaginary 5) (imaginary 5)) (imaginary 10))))
    1.91 +
    1.92 +(deftest complex-subtraction
    1.93 +  (is (= (- (complex 1 2) (complex 1 2)) 0))
    1.94 +  (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9)))
    1.95 +  (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9)))
    1.96 +  (is (= (- (complex 1 2) 3) (complex -2 2)))
    1.97 +  (is (= (- 3 (complex 1 2)) (complex 2 -2)))
    1.98 +  (is (= (- (complex 1 2) -1) (complex 2 2)))
    1.99 +  (is (= (- -1 (complex 1 2)) (complex -2 -2)))
   1.100 +  (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4)))
   1.101 +  (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4)))
   1.102 +  (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3)))
   1.103 +  (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3)))
   1.104 +  (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9)))
   1.105 +  (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9)))
   1.106 +  (is (= (- (complex -3 -7) (complex -3 -7)) 0))
   1.107 +  (is (= (- (complex -3 -7) 3) (complex -6 -7)))
   1.108 +  (is (= (- 3 (complex -3 -7)) (complex 6 7)))
   1.109 +  (is (= (- (complex -3 -7) -1) (complex -2 -7)))
   1.110 +  (is (= (- -1 (complex -3 -7)) (complex 2 7)))
   1.111 +  (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5)))
   1.112 +  (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5)))
   1.113 +  (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12)))
   1.114 +  (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12)))
   1.115 +  (is (= (- 3 (complex 1 2)) (complex 2 -2)))
   1.116 +  (is (= (- (complex 1 2) 3) (complex -2 2)))
   1.117 +  (is (= (- 3 (complex -3 -7)) (complex 6 7)))
   1.118 +  (is (= (- (complex -3 -7) 3) (complex -6 -7)))
   1.119 +  (is (= (- 3 (imaginary -2)) (complex 3 2)))
   1.120 +  (is (= (- (imaginary -2) 3) (complex -3 -2)))
   1.121 +  (is (= (- 3 (imaginary 5)) (complex 3 -5)))
   1.122 +  (is (= (- (imaginary 5) 3) (complex -3 5)))
   1.123 +  (is (= (- -1 (complex 1 2)) (complex -2 -2)))
   1.124 +  (is (= (- (complex 1 2) -1) (complex 2 2)))
   1.125 +  (is (= (- -1 (complex -3 -7)) (complex 2 7)))
   1.126 +  (is (= (- (complex -3 -7) -1) (complex -2 -7)))
   1.127 +  (is (= (- -1 (imaginary -2)) (complex -1 2)))
   1.128 +  (is (= (- (imaginary -2) -1) (complex 1 -2)))
   1.129 +  (is (= (- -1 (imaginary 5)) (complex -1 -5)))
   1.130 +  (is (= (- (imaginary 5) -1) (complex 1 5)))
   1.131 +  (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4)))
   1.132 +  (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4)))
   1.133 +  (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5)))
   1.134 +  (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5)))
   1.135 +  (is (= (- (imaginary -2) 3) (complex -3 -2)))
   1.136 +  (is (= (- 3 (imaginary -2)) (complex 3 2)))
   1.137 +  (is (= (- (imaginary -2) -1) (complex 1 -2)))
   1.138 +  (is (= (- -1 (imaginary -2)) (complex -1 2)))
   1.139 +  (is (= (- (imaginary -2) (imaginary -2)) 0))
   1.140 +  (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7)))
   1.141 +  (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7)))
   1.142 +  (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3)))
   1.143 +  (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3)))
   1.144 +  (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12)))
   1.145 +  (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12)))
   1.146 +  (is (= (- (imaginary 5) 3) (complex -3 5)))
   1.147 +  (is (= (- 3 (imaginary 5)) (complex 3 -5)))
   1.148 +  (is (= (- (imaginary 5) -1) (complex 1 5)))
   1.149 +  (is (= (- -1 (imaginary 5)) (complex -1 -5)))
   1.150 +  (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7)))
   1.151 +  (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7)))
   1.152 +  (is (= (- (imaginary 5) (imaginary 5)) 0)))
   1.153 +
   1.154 +(deftest complex-multiplication
   1.155 +  (is (= (* (complex 1 2) (complex 1 2)) (complex -3 4)))
   1.156 +  (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13)))
   1.157 +  (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13)))
   1.158 +  (is (= (* (complex 1 2) 3) (complex 3 6)))
   1.159 +  (is (= (* 3 (complex 1 2)) (complex 3 6)))
   1.160 +  (is (= (* (complex 1 2) -1) (complex -1 -2)))
   1.161 +  (is (= (* -1 (complex 1 2)) (complex -1 -2)))
   1.162 +  (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2)))
   1.163 +  (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2)))
   1.164 +  (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5)))
   1.165 +  (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5)))
   1.166 +  (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13)))
   1.167 +  (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13)))
   1.168 +  (is (= (* (complex -3 -7) (complex -3 -7)) (complex -40 42)))
   1.169 +  (is (= (* (complex -3 -7) 3) (complex -9 -21)))
   1.170 +  (is (= (* 3 (complex -3 -7)) (complex -9 -21)))
   1.171 +  (is (= (* (complex -3 -7) -1) (complex 3 7)))
   1.172 +  (is (= (* -1 (complex -3 -7)) (complex 3 7)))
   1.173 +  (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6)))
   1.174 +  (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6)))
   1.175 +  (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15)))
   1.176 +  (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15)))
   1.177 +  (is (= (* 3 (complex 1 2)) (complex 3 6)))
   1.178 +  (is (= (* (complex 1 2) 3) (complex 3 6)))
   1.179 +  (is (= (* 3 (complex -3 -7)) (complex -9 -21)))
   1.180 +  (is (= (* (complex -3 -7) 3) (complex -9 -21)))
   1.181 +  (is (= (* 3 (imaginary -2)) (imaginary -6)))
   1.182 +  (is (= (* (imaginary -2) 3) (imaginary -6)))
   1.183 +  (is (= (* 3 (imaginary 5)) (imaginary 15)))
   1.184 +  (is (= (* (imaginary 5) 3) (imaginary 15)))
   1.185 +  (is (= (* -1 (complex 1 2)) (complex -1 -2)))
   1.186 +  (is (= (* (complex 1 2) -1) (complex -1 -2)))
   1.187 +  (is (= (* -1 (complex -3 -7)) (complex 3 7)))
   1.188 +  (is (= (* (complex -3 -7) -1) (complex 3 7)))
   1.189 +  (is (= (* -1 (imaginary -2)) (imaginary 2)))
   1.190 +  (is (= (* (imaginary -2) -1) (imaginary 2)))
   1.191 +  (is (= (* -1 (imaginary 5)) (imaginary -5)))
   1.192 +  (is (= (* (imaginary 5) -1) (imaginary -5)))
   1.193 +  (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2)))
   1.194 +  (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2)))
   1.195 +  (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6)))
   1.196 +  (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6)))
   1.197 +  (is (= (* (imaginary -2) 3) (imaginary -6)))
   1.198 +  (is (= (* 3 (imaginary -2)) (imaginary -6)))
   1.199 +  (is (= (* (imaginary -2) -1) (imaginary 2)))
   1.200 +  (is (= (* -1 (imaginary -2)) (imaginary 2)))
   1.201 +  (is (= (* (imaginary -2) (imaginary -2)) -4))
   1.202 +  (is (= (* (imaginary -2) (imaginary 5)) 10))
   1.203 +  (is (= (* (imaginary 5) (imaginary -2)) 10))
   1.204 +  (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5)))
   1.205 +  (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5)))
   1.206 +  (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15)))
   1.207 +  (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15)))
   1.208 +  (is (= (* (imaginary 5) 3) (imaginary 15)))
   1.209 +  (is (= (* 3 (imaginary 5)) (imaginary 15)))
   1.210 +  (is (= (* (imaginary 5) -1) (imaginary -5)))
   1.211 +  (is (= (* -1 (imaginary 5)) (imaginary -5)))
   1.212 +  (is (= (* (imaginary 5) (imaginary -2)) 10))
   1.213 +  (is (= (* (imaginary -2) (imaginary 5)) 10))
   1.214 +  (is (= (* (imaginary 5) (imaginary 5)) -25)))
   1.215 +
   1.216 +(deftest complex-division
   1.217 +  (is (= (/ (complex 1 2) (complex 1 2)) 1))
   1.218 +  (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58)))
   1.219 +  (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5)))
   1.220 +  (is (= (/ (complex 1 2) 3) (complex 1/3 2/3)))
   1.221 +  (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5)))
   1.222 +  (is (= (/ (complex 1 2) -1) (complex -1 -2)))
   1.223 +  (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5)))
   1.224 +  (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2)))
   1.225 +  (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5)))
   1.226 +  (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5)))
   1.227 +  (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1)))
   1.228 +  (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5)))
   1.229 +  (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58)))
   1.230 +  (is (= (/ (complex -3 -7) (complex -3 -7)) 1))
   1.231 +  (is (= (/ (complex -3 -7) 3) (complex -1 -7/3)))
   1.232 +  (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58)))
   1.233 +  (is (= (/ (complex -3 -7) -1) (complex 3 7)))
   1.234 +  (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58)))
   1.235 +  (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2)))
   1.236 +  (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29)))
   1.237 +  (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5)))
   1.238 +  (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58)))
   1.239 +  (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5)))
   1.240 +  (is (= (/ (complex 1 2) 3) (complex 1/3 2/3)))
   1.241 +  (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58)))
   1.242 +  (is (= (/ (complex -3 -7) 3) (complex -1 -7/3)))
   1.243 +  #_(is (= (/ 3 (imaginary -2)) (imaginary 1.5)))
   1.244 +  (is (= (/ (imaginary -2) 3) (imaginary -2/3)))
   1.245 +  (is (= (/ 3 (imaginary 5)) (imaginary -3/5)))
   1.246 +  (is (= (/ (imaginary 5) 3) (imaginary 5/3)))
   1.247 +  (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5)))
   1.248 +  (is (= (/ (complex 1 2) -1) (complex -1 -2)))
   1.249 +  (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58)))
   1.250 +  (is (= (/ (complex -3 -7) -1) (complex 3 7)))
   1.251 +  (is (= (/ -1 (imaginary -2)) (imaginary -1/2)))
   1.252 +  (is (= (/ (imaginary -2) -1) (imaginary 2)))
   1.253 +  (is (= (/ -1 (imaginary 5)) (imaginary 1/5)))
   1.254 +  (is (= (/ (imaginary 5) -1) (imaginary -5)))
   1.255 +  (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5)))
   1.256 +  (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2)))
   1.257 +  (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29)))
   1.258 +  (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2)))
   1.259 +  (is (= (/ (imaginary -2) 3) (imaginary -2/3)))
   1.260 +  (is (= (/ 3 (imaginary -2)) (imaginary 3/2)))
   1.261 +  (is (= (/ (imaginary -2) -1) (imaginary 2)))
   1.262 +  (is (= (/ -1 (imaginary -2)) (imaginary -1/2)))
   1.263 +  (is (= (/ (imaginary -2) (imaginary -2)) 1))
   1.264 +  (is (= (/ (imaginary -2) (imaginary 5)) -2/5))
   1.265 +  (is (= (/ (imaginary 5) (imaginary -2)) -5/2))
   1.266 +  (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1)))
   1.267 +  (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5)))
   1.268 +  (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58)))
   1.269 +  (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5)))
   1.270 +  (is (= (/ (imaginary 5) 3) (imaginary 5/3)))
   1.271 +  (is (= (/ 3 (imaginary 5)) (imaginary -3/5)))
   1.272 +  (is (= (/ (imaginary 5) -1) (imaginary -5)))
   1.273 +  (is (= (/ -1 (imaginary 5)) (imaginary 1/5)))
   1.274 +  (is (= (/ (imaginary 5) (imaginary -2)) -5/2))
   1.275 +  (is (= (/ (imaginary -2) (imaginary 5)) -2/5))
   1.276 +  (is (= (/ (imaginary 5) (imaginary 5)) 1)))
   1.277 +
   1.278 +(deftest complex-conjugate
   1.279 +  (is (= (conjugate (complex 1 2)) (complex 1 -2)))
   1.280 +  (is (= (conjugate (complex -3 -7)) (complex -3 7)))
   1.281 +  (is (= (conjugate (imaginary -2)) (imaginary 2)))
   1.282 +  (is (= (conjugate (imaginary 5)) (imaginary -5))))
   1.283 +
   1.284 +(deftest complex-abs
   1.285 +  (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2)
   1.286 +	     (complex -3 -7) (imaginary -2) (imaginary 5)]]
   1.287 +    (is (approx= (* c (conjugate c))
   1.288 +		 (sqr (abs c))
   1.289 +		 1e-14))))
   1.290 +
   1.291 +(deftest complex-sqrt
   1.292 +  (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2)
   1.293 +	     (complex -3 -7) (imaginary -2) (imaginary 5)]]
   1.294 +    (let [r (sqrt c)]
   1.295 +      (is (approx= c (sqr r) 1e-14))
   1.296 +      (is (>= (real r) 0)))))
   1.297 +
   1.298 +(deftest complex-exp
   1.299 +  (is (approx= (exp (complex 1 2))
   1.300 +	       (complex -1.1312043837568135 2.4717266720048188)
   1.301 +	       1e-14))
   1.302 +  (is (approx= (exp (complex 2 3))
   1.303 +	       (complex -7.3151100949011028 1.0427436562359045)
   1.304 +	       1e-14))
   1.305 +  (is (approx= (exp (complex 4 -2))
   1.306 +	       (complex -22.720847417619233 -49.645957334580565)
   1.307 +	       1e-14))
   1.308 +  (is (approx= (exp (complex 3 -7))
   1.309 +	       (complex 15.142531566086868 -13.195928586605717)
   1.310 +	       1e-14))
   1.311 +  (is (approx= (exp (imaginary -2))
   1.312 +	       (complex -0.41614683654714241 -0.90929742682568171)
   1.313 +	       1e-14))
   1.314 +  (is (approx= (exp (imaginary 5))
   1.315 +	       (complex 0.2836621854632263 -0.95892427466313845)
   1.316 +	       1e-14)))