annotate 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
rev   line source
rlm@10 1 ;; Test routines for complex-numbers.clj
rlm@10 2
rlm@10 3 ;; by Konrad Hinsen
rlm@10 4 ;; last updated April 2, 2009
rlm@10 5
rlm@10 6 ;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use
rlm@10 7 ;; and distribution terms for this software are covered by the Eclipse
rlm@10 8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 9 ;; which can be found in the file epl-v10.html at the root of this
rlm@10 10 ;; distribution. By using this software in any fashion, you are
rlm@10 11 ;; agreeing to be bound by the terms of this license. You must not
rlm@10 12 ;; remove this notice, or any other, from this software.
rlm@10 13
rlm@10 14 (ns clojure.contrib.test-complex-numbers
rlm@10 15 (:refer-clojure :exclude [+ - * / = < > <= >=])
rlm@10 16 (:use [clojure.test
rlm@10 17 :only (deftest is are run-tests)]
rlm@10 18 [clojure.contrib.generic.arithmetic
rlm@10 19 :only (+ - * /)]
rlm@10 20 [clojure.contrib.generic.comparison
rlm@10 21 :only (= < > <= >=)]
rlm@10 22 [clojure.contrib.generic.math-functions
rlm@10 23 :only (abs approx= conjugate exp sqr sqrt)]
rlm@10 24 [clojure.contrib.complex-numbers
rlm@10 25 :only (complex imaginary real imag)]))
rlm@10 26
rlm@10 27 (deftest complex-addition
rlm@10 28 (is (= (+ (complex 1 2) (complex 1 2)) (complex 2 4)))
rlm@10 29 (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5)))
rlm@10 30 (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5)))
rlm@10 31 (is (= (+ (complex 1 2) 3) (complex 4 2)))
rlm@10 32 (is (= (+ 3 (complex 1 2)) (complex 4 2)))
rlm@10 33 (is (= (+ (complex 1 2) -1) (imaginary 2)))
rlm@10 34 (is (= (+ -1 (complex 1 2)) (imaginary 2)))
rlm@10 35 (is (= (+ (complex 1 2) (imaginary -2)) 1))
rlm@10 36 (is (= (+ (imaginary -2) (complex 1 2)) 1))
rlm@10 37 (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7)))
rlm@10 38 (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7)))
rlm@10 39 (is (= (+ (complex -3 -7) (complex 1 2)) (complex -2 -5)))
rlm@10 40 (is (= (+ (complex 1 2) (complex -3 -7)) (complex -2 -5)))
rlm@10 41 (is (= (+ (complex -3 -7) (complex -3 -7)) (complex -6 -14)))
rlm@10 42 (is (= (+ (complex -3 -7) 3) (imaginary -7)))
rlm@10 43 (is (= (+ 3 (complex -3 -7)) (imaginary -7)))
rlm@10 44 (is (= (+ (complex -3 -7) -1) (complex -4 -7)))
rlm@10 45 (is (= (+ -1 (complex -3 -7)) (complex -4 -7)))
rlm@10 46 (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9)))
rlm@10 47 (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9)))
rlm@10 48 (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2)))
rlm@10 49 (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2)))
rlm@10 50 (is (= (+ 3 (complex 1 2)) (complex 4 2)))
rlm@10 51 (is (= (+ (complex 1 2) 3) (complex 4 2)))
rlm@10 52 (is (= (+ 3 (complex -3 -7)) (imaginary -7)))
rlm@10 53 (is (= (+ (complex -3 -7) 3) (imaginary -7)))
rlm@10 54 (is (= (+ 3 (imaginary -2)) (complex 3 -2)))
rlm@10 55 (is (= (+ (imaginary -2) 3) (complex 3 -2)))
rlm@10 56 (is (= (+ 3 (imaginary 5)) (complex 3 5)))
rlm@10 57 (is (= (+ (imaginary 5) 3) (complex 3 5)))
rlm@10 58 (is (= (+ -1 (complex 1 2)) (imaginary 2)))
rlm@10 59 (is (= (+ (complex 1 2) -1) (imaginary 2)))
rlm@10 60 (is (= (+ -1 (complex -3 -7)) (complex -4 -7)))
rlm@10 61 (is (= (+ (complex -3 -7) -1) (complex -4 -7)))
rlm@10 62 (is (= (+ -1 (imaginary -2)) (complex -1 -2)))
rlm@10 63 (is (= (+ (imaginary -2) -1) (complex -1 -2)))
rlm@10 64 (is (= (+ -1 (imaginary 5)) (complex -1 5)))
rlm@10 65 (is (= (+ (imaginary 5) -1) (complex -1 5)))
rlm@10 66 (is (= (+ (imaginary -2) (complex 1 2)) 1))
rlm@10 67 (is (= (+ (complex 1 2) (imaginary -2)) 1))
rlm@10 68 (is (= (+ (imaginary -2) (complex -3 -7)) (complex -3 -9)))
rlm@10 69 (is (= (+ (complex -3 -7) (imaginary -2)) (complex -3 -9)))
rlm@10 70 (is (= (+ (imaginary -2) 3) (complex 3 -2)))
rlm@10 71 (is (= (+ 3 (imaginary -2)) (complex 3 -2)))
rlm@10 72 (is (= (+ (imaginary -2) -1) (complex -1 -2)))
rlm@10 73 (is (= (+ -1 (imaginary -2)) (complex -1 -2)))
rlm@10 74 (is (= (+ (imaginary -2) (imaginary -2)) (imaginary -4)))
rlm@10 75 (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3)))
rlm@10 76 (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3)))
rlm@10 77 (is (= (+ (imaginary 5) (complex 1 2)) (complex 1 7)))
rlm@10 78 (is (= (+ (complex 1 2) (imaginary 5)) (complex 1 7)))
rlm@10 79 (is (= (+ (imaginary 5) (complex -3 -7)) (complex -3 -2)))
rlm@10 80 (is (= (+ (complex -3 -7) (imaginary 5)) (complex -3 -2)))
rlm@10 81 (is (= (+ (imaginary 5) 3) (complex 3 5)))
rlm@10 82 (is (= (+ 3 (imaginary 5)) (complex 3 5)))
rlm@10 83 (is (= (+ (imaginary 5) -1) (complex -1 5)))
rlm@10 84 (is (= (+ -1 (imaginary 5)) (complex -1 5)))
rlm@10 85 (is (= (+ (imaginary 5) (imaginary -2)) (imaginary 3)))
rlm@10 86 (is (= (+ (imaginary -2) (imaginary 5)) (imaginary 3)))
rlm@10 87 (is (= (+ (imaginary 5) (imaginary 5)) (imaginary 10))))
rlm@10 88
rlm@10 89 (deftest complex-subtraction
rlm@10 90 (is (= (- (complex 1 2) (complex 1 2)) 0))
rlm@10 91 (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9)))
rlm@10 92 (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9)))
rlm@10 93 (is (= (- (complex 1 2) 3) (complex -2 2)))
rlm@10 94 (is (= (- 3 (complex 1 2)) (complex 2 -2)))
rlm@10 95 (is (= (- (complex 1 2) -1) (complex 2 2)))
rlm@10 96 (is (= (- -1 (complex 1 2)) (complex -2 -2)))
rlm@10 97 (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4)))
rlm@10 98 (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4)))
rlm@10 99 (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3)))
rlm@10 100 (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3)))
rlm@10 101 (is (= (- (complex -3 -7) (complex 1 2)) (complex -4 -9)))
rlm@10 102 (is (= (- (complex 1 2) (complex -3 -7)) (complex 4 9)))
rlm@10 103 (is (= (- (complex -3 -7) (complex -3 -7)) 0))
rlm@10 104 (is (= (- (complex -3 -7) 3) (complex -6 -7)))
rlm@10 105 (is (= (- 3 (complex -3 -7)) (complex 6 7)))
rlm@10 106 (is (= (- (complex -3 -7) -1) (complex -2 -7)))
rlm@10 107 (is (= (- -1 (complex -3 -7)) (complex 2 7)))
rlm@10 108 (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5)))
rlm@10 109 (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5)))
rlm@10 110 (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12)))
rlm@10 111 (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12)))
rlm@10 112 (is (= (- 3 (complex 1 2)) (complex 2 -2)))
rlm@10 113 (is (= (- (complex 1 2) 3) (complex -2 2)))
rlm@10 114 (is (= (- 3 (complex -3 -7)) (complex 6 7)))
rlm@10 115 (is (= (- (complex -3 -7) 3) (complex -6 -7)))
rlm@10 116 (is (= (- 3 (imaginary -2)) (complex 3 2)))
rlm@10 117 (is (= (- (imaginary -2) 3) (complex -3 -2)))
rlm@10 118 (is (= (- 3 (imaginary 5)) (complex 3 -5)))
rlm@10 119 (is (= (- (imaginary 5) 3) (complex -3 5)))
rlm@10 120 (is (= (- -1 (complex 1 2)) (complex -2 -2)))
rlm@10 121 (is (= (- (complex 1 2) -1) (complex 2 2)))
rlm@10 122 (is (= (- -1 (complex -3 -7)) (complex 2 7)))
rlm@10 123 (is (= (- (complex -3 -7) -1) (complex -2 -7)))
rlm@10 124 (is (= (- -1 (imaginary -2)) (complex -1 2)))
rlm@10 125 (is (= (- (imaginary -2) -1) (complex 1 -2)))
rlm@10 126 (is (= (- -1 (imaginary 5)) (complex -1 -5)))
rlm@10 127 (is (= (- (imaginary 5) -1) (complex 1 5)))
rlm@10 128 (is (= (- (imaginary -2) (complex 1 2)) (complex -1 -4)))
rlm@10 129 (is (= (- (complex 1 2) (imaginary -2)) (complex 1 4)))
rlm@10 130 (is (= (- (imaginary -2) (complex -3 -7)) (complex 3 5)))
rlm@10 131 (is (= (- (complex -3 -7) (imaginary -2)) (complex -3 -5)))
rlm@10 132 (is (= (- (imaginary -2) 3) (complex -3 -2)))
rlm@10 133 (is (= (- 3 (imaginary -2)) (complex 3 2)))
rlm@10 134 (is (= (- (imaginary -2) -1) (complex 1 -2)))
rlm@10 135 (is (= (- -1 (imaginary -2)) (complex -1 2)))
rlm@10 136 (is (= (- (imaginary -2) (imaginary -2)) 0))
rlm@10 137 (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7)))
rlm@10 138 (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7)))
rlm@10 139 (is (= (- (imaginary 5) (complex 1 2)) (complex -1 3)))
rlm@10 140 (is (= (- (complex 1 2) (imaginary 5)) (complex 1 -3)))
rlm@10 141 (is (= (- (imaginary 5) (complex -3 -7)) (complex 3 12)))
rlm@10 142 (is (= (- (complex -3 -7) (imaginary 5)) (complex -3 -12)))
rlm@10 143 (is (= (- (imaginary 5) 3) (complex -3 5)))
rlm@10 144 (is (= (- 3 (imaginary 5)) (complex 3 -5)))
rlm@10 145 (is (= (- (imaginary 5) -1) (complex 1 5)))
rlm@10 146 (is (= (- -1 (imaginary 5)) (complex -1 -5)))
rlm@10 147 (is (= (- (imaginary 5) (imaginary -2)) (imaginary 7)))
rlm@10 148 (is (= (- (imaginary -2) (imaginary 5)) (imaginary -7)))
rlm@10 149 (is (= (- (imaginary 5) (imaginary 5)) 0)))
rlm@10 150
rlm@10 151 (deftest complex-multiplication
rlm@10 152 (is (= (* (complex 1 2) (complex 1 2)) (complex -3 4)))
rlm@10 153 (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13)))
rlm@10 154 (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13)))
rlm@10 155 (is (= (* (complex 1 2) 3) (complex 3 6)))
rlm@10 156 (is (= (* 3 (complex 1 2)) (complex 3 6)))
rlm@10 157 (is (= (* (complex 1 2) -1) (complex -1 -2)))
rlm@10 158 (is (= (* -1 (complex 1 2)) (complex -1 -2)))
rlm@10 159 (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2)))
rlm@10 160 (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2)))
rlm@10 161 (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5)))
rlm@10 162 (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5)))
rlm@10 163 (is (= (* (complex -3 -7) (complex 1 2)) (complex 11 -13)))
rlm@10 164 (is (= (* (complex 1 2) (complex -3 -7)) (complex 11 -13)))
rlm@10 165 (is (= (* (complex -3 -7) (complex -3 -7)) (complex -40 42)))
rlm@10 166 (is (= (* (complex -3 -7) 3) (complex -9 -21)))
rlm@10 167 (is (= (* 3 (complex -3 -7)) (complex -9 -21)))
rlm@10 168 (is (= (* (complex -3 -7) -1) (complex 3 7)))
rlm@10 169 (is (= (* -1 (complex -3 -7)) (complex 3 7)))
rlm@10 170 (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6)))
rlm@10 171 (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6)))
rlm@10 172 (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15)))
rlm@10 173 (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15)))
rlm@10 174 (is (= (* 3 (complex 1 2)) (complex 3 6)))
rlm@10 175 (is (= (* (complex 1 2) 3) (complex 3 6)))
rlm@10 176 (is (= (* 3 (complex -3 -7)) (complex -9 -21)))
rlm@10 177 (is (= (* (complex -3 -7) 3) (complex -9 -21)))
rlm@10 178 (is (= (* 3 (imaginary -2)) (imaginary -6)))
rlm@10 179 (is (= (* (imaginary -2) 3) (imaginary -6)))
rlm@10 180 (is (= (* 3 (imaginary 5)) (imaginary 15)))
rlm@10 181 (is (= (* (imaginary 5) 3) (imaginary 15)))
rlm@10 182 (is (= (* -1 (complex 1 2)) (complex -1 -2)))
rlm@10 183 (is (= (* (complex 1 2) -1) (complex -1 -2)))
rlm@10 184 (is (= (* -1 (complex -3 -7)) (complex 3 7)))
rlm@10 185 (is (= (* (complex -3 -7) -1) (complex 3 7)))
rlm@10 186 (is (= (* -1 (imaginary -2)) (imaginary 2)))
rlm@10 187 (is (= (* (imaginary -2) -1) (imaginary 2)))
rlm@10 188 (is (= (* -1 (imaginary 5)) (imaginary -5)))
rlm@10 189 (is (= (* (imaginary 5) -1) (imaginary -5)))
rlm@10 190 (is (= (* (imaginary -2) (complex 1 2)) (complex 4 -2)))
rlm@10 191 (is (= (* (complex 1 2) (imaginary -2)) (complex 4 -2)))
rlm@10 192 (is (= (* (imaginary -2) (complex -3 -7)) (complex -14 6)))
rlm@10 193 (is (= (* (complex -3 -7) (imaginary -2)) (complex -14 6)))
rlm@10 194 (is (= (* (imaginary -2) 3) (imaginary -6)))
rlm@10 195 (is (= (* 3 (imaginary -2)) (imaginary -6)))
rlm@10 196 (is (= (* (imaginary -2) -1) (imaginary 2)))
rlm@10 197 (is (= (* -1 (imaginary -2)) (imaginary 2)))
rlm@10 198 (is (= (* (imaginary -2) (imaginary -2)) -4))
rlm@10 199 (is (= (* (imaginary -2) (imaginary 5)) 10))
rlm@10 200 (is (= (* (imaginary 5) (imaginary -2)) 10))
rlm@10 201 (is (= (* (imaginary 5) (complex 1 2)) (complex -10 5)))
rlm@10 202 (is (= (* (complex 1 2) (imaginary 5)) (complex -10 5)))
rlm@10 203 (is (= (* (imaginary 5) (complex -3 -7)) (complex 35 -15)))
rlm@10 204 (is (= (* (complex -3 -7) (imaginary 5)) (complex 35 -15)))
rlm@10 205 (is (= (* (imaginary 5) 3) (imaginary 15)))
rlm@10 206 (is (= (* 3 (imaginary 5)) (imaginary 15)))
rlm@10 207 (is (= (* (imaginary 5) -1) (imaginary -5)))
rlm@10 208 (is (= (* -1 (imaginary 5)) (imaginary -5)))
rlm@10 209 (is (= (* (imaginary 5) (imaginary -2)) 10))
rlm@10 210 (is (= (* (imaginary -2) (imaginary 5)) 10))
rlm@10 211 (is (= (* (imaginary 5) (imaginary 5)) -25)))
rlm@10 212
rlm@10 213 (deftest complex-division
rlm@10 214 (is (= (/ (complex 1 2) (complex 1 2)) 1))
rlm@10 215 (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58)))
rlm@10 216 (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5)))
rlm@10 217 (is (= (/ (complex 1 2) 3) (complex 1/3 2/3)))
rlm@10 218 (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5)))
rlm@10 219 (is (= (/ (complex 1 2) -1) (complex -1 -2)))
rlm@10 220 (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5)))
rlm@10 221 (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2)))
rlm@10 222 (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5)))
rlm@10 223 (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5)))
rlm@10 224 (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1)))
rlm@10 225 (is (= (/ (complex -3 -7) (complex 1 2)) (complex -17/5 -1/5)))
rlm@10 226 (is (= (/ (complex 1 2) (complex -3 -7)) (complex -17/58 1/58)))
rlm@10 227 (is (= (/ (complex -3 -7) (complex -3 -7)) 1))
rlm@10 228 (is (= (/ (complex -3 -7) 3) (complex -1 -7/3)))
rlm@10 229 (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58)))
rlm@10 230 (is (= (/ (complex -3 -7) -1) (complex 3 7)))
rlm@10 231 (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58)))
rlm@10 232 (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2)))
rlm@10 233 (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29)))
rlm@10 234 (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5)))
rlm@10 235 (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58)))
rlm@10 236 (is (= (/ 3 (complex 1 2)) (complex 3/5 -6/5)))
rlm@10 237 (is (= (/ (complex 1 2) 3) (complex 1/3 2/3)))
rlm@10 238 (is (= (/ 3 (complex -3 -7)) (complex -9/58 21/58)))
rlm@10 239 (is (= (/ (complex -3 -7) 3) (complex -1 -7/3)))
rlm@10 240 #_(is (= (/ 3 (imaginary -2)) (imaginary 1.5)))
rlm@10 241 (is (= (/ (imaginary -2) 3) (imaginary -2/3)))
rlm@10 242 (is (= (/ 3 (imaginary 5)) (imaginary -3/5)))
rlm@10 243 (is (= (/ (imaginary 5) 3) (imaginary 5/3)))
rlm@10 244 (is (= (/ -1 (complex 1 2)) (complex -1/5 2/5)))
rlm@10 245 (is (= (/ (complex 1 2) -1) (complex -1 -2)))
rlm@10 246 (is (= (/ -1 (complex -3 -7)) (complex 3/58 -7/58)))
rlm@10 247 (is (= (/ (complex -3 -7) -1) (complex 3 7)))
rlm@10 248 (is (= (/ -1 (imaginary -2)) (imaginary -1/2)))
rlm@10 249 (is (= (/ (imaginary -2) -1) (imaginary 2)))
rlm@10 250 (is (= (/ -1 (imaginary 5)) (imaginary 1/5)))
rlm@10 251 (is (= (/ (imaginary 5) -1) (imaginary -5)))
rlm@10 252 (is (= (/ (imaginary -2) (complex 1 2)) (complex -4/5 -2/5)))
rlm@10 253 (is (= (/ (complex 1 2) (imaginary -2)) (complex -1 1/2)))
rlm@10 254 (is (= (/ (imaginary -2) (complex -3 -7)) (complex 7/29 3/29)))
rlm@10 255 (is (= (/ (complex -3 -7) (imaginary -2)) (complex 7/2 -3/2)))
rlm@10 256 (is (= (/ (imaginary -2) 3) (imaginary -2/3)))
rlm@10 257 (is (= (/ 3 (imaginary -2)) (imaginary 3/2)))
rlm@10 258 (is (= (/ (imaginary -2) -1) (imaginary 2)))
rlm@10 259 (is (= (/ -1 (imaginary -2)) (imaginary -1/2)))
rlm@10 260 (is (= (/ (imaginary -2) (imaginary -2)) 1))
rlm@10 261 (is (= (/ (imaginary -2) (imaginary 5)) -2/5))
rlm@10 262 (is (= (/ (imaginary 5) (imaginary -2)) -5/2))
rlm@10 263 (is (= (/ (imaginary 5) (complex 1 2)) (complex 2 1)))
rlm@10 264 (is (= (/ (complex 1 2) (imaginary 5)) (complex 2/5 -1/5)))
rlm@10 265 (is (= (/ (imaginary 5) (complex -3 -7)) (complex -35/58 -15/58)))
rlm@10 266 (is (= (/ (complex -3 -7) (imaginary 5)) (complex -7/5 3/5)))
rlm@10 267 (is (= (/ (imaginary 5) 3) (imaginary 5/3)))
rlm@10 268 (is (= (/ 3 (imaginary 5)) (imaginary -3/5)))
rlm@10 269 (is (= (/ (imaginary 5) -1) (imaginary -5)))
rlm@10 270 (is (= (/ -1 (imaginary 5)) (imaginary 1/5)))
rlm@10 271 (is (= (/ (imaginary 5) (imaginary -2)) -5/2))
rlm@10 272 (is (= (/ (imaginary -2) (imaginary 5)) -2/5))
rlm@10 273 (is (= (/ (imaginary 5) (imaginary 5)) 1)))
rlm@10 274
rlm@10 275 (deftest complex-conjugate
rlm@10 276 (is (= (conjugate (complex 1 2)) (complex 1 -2)))
rlm@10 277 (is (= (conjugate (complex -3 -7)) (complex -3 7)))
rlm@10 278 (is (= (conjugate (imaginary -2)) (imaginary 2)))
rlm@10 279 (is (= (conjugate (imaginary 5)) (imaginary -5))))
rlm@10 280
rlm@10 281 (deftest complex-abs
rlm@10 282 (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2)
rlm@10 283 (complex -3 -7) (imaginary -2) (imaginary 5)]]
rlm@10 284 (is (approx= (* c (conjugate c))
rlm@10 285 (sqr (abs c))
rlm@10 286 1e-14))))
rlm@10 287
rlm@10 288 (deftest complex-sqrt
rlm@10 289 (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2)
rlm@10 290 (complex -3 -7) (imaginary -2) (imaginary 5)]]
rlm@10 291 (let [r (sqrt c)]
rlm@10 292 (is (approx= c (sqr r) 1e-14))
rlm@10 293 (is (>= (real r) 0)))))
rlm@10 294
rlm@10 295 (deftest complex-exp
rlm@10 296 (is (approx= (exp (complex 1 2))
rlm@10 297 (complex -1.1312043837568135 2.4717266720048188)
rlm@10 298 1e-14))
rlm@10 299 (is (approx= (exp (complex 2 3))
rlm@10 300 (complex -7.3151100949011028 1.0427436562359045)
rlm@10 301 1e-14))
rlm@10 302 (is (approx= (exp (complex 4 -2))
rlm@10 303 (complex -22.720847417619233 -49.645957334580565)
rlm@10 304 1e-14))
rlm@10 305 (is (approx= (exp (complex 3 -7))
rlm@10 306 (complex 15.142531566086868 -13.195928586605717)
rlm@10 307 1e-14))
rlm@10 308 (is (approx= (exp (imaginary -2))
rlm@10 309 (complex -0.41614683654714241 -0.90929742682568171)
rlm@10 310 1e-14))
rlm@10 311 (is (approx= (exp (imaginary 5))
rlm@10 312 (complex 0.2836621854632263 -0.95892427466313845)
rlm@10 313 1e-14)))