diff options
author | Eduardo Julian | 2017-01-27 06:54:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-01-27 06:54:08 -0400 |
commit | 9e87e07dc32e2c8acc5d95d2e56babded93fc7ac (patch) | |
tree | 4024ee25d0bdfdf91cbd5f1304275dfac0116deb /stdlib/test | |
parent | 3f76b52f46b58ab0d1dd8846edb43db95c391219 (diff) |
- Added Number implementation for Complex.
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/math/complex.lux | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/stdlib/test/test/lux/math/complex.lux b/stdlib/test/test/lux/math/complex.lux index 487e7ba59..0cb5be426 100644 --- a/stdlib/test/test/lux/math/complex.lux +++ b/stdlib/test/test/lux/math/complex.lux @@ -64,25 +64,27 @@ ($_ seq (assert "Absolute value of complex >= absolute value of any of the parts." (let [r+i (&;complex real imaginary) - abs (&;c.abs r+i)] + abs (get@ #&;real (&;c.abs r+i))] (and (r.>= (r/abs real) abs) (r.>= (r/abs imaginary) abs)))) (assert "The absolute value of a complex number involving a NaN on either dimension, results in a NaN value." - (and (number;nan? (&;c.abs (&;complex number;nan imaginary))) - (number;nan? (&;c.abs (&;complex real number;nan))))) + (and (number;nan? (get@ #&;real (&;c.abs (&;complex number;nan imaginary)))) + (number;nan? (get@ #&;real (&;c.abs (&;complex real number;nan)))))) (assert "The absolute value of a complex number involving an infinity on either dimension, results in an infinite value." - (and (r.= number;+inf (&;c.abs (&;complex number;+inf imaginary))) - (r.= number;+inf (&;c.abs (&;complex real number;+inf))) - (r.= number;+inf (&;c.abs (&;complex number;-inf imaginary))) - (r.= number;+inf (&;c.abs (&;complex real number;-inf))))) + (and (r.= number;+inf (get@ #&;real (&;c.abs (&;complex number;+inf imaginary)))) + (r.= number;+inf (get@ #&;real (&;c.abs (&;complex real number;+inf)))) + (r.= number;+inf (get@ #&;real (&;c.abs (&;complex number;-inf imaginary)))) + (r.= number;+inf (get@ #&;real (&;c.abs (&;complex real number;-inf)))))) )) (test: "Addidion, substraction, multiplication and division" [x gen-complex y gen-complex - factor gen-dim] + factor gen-dim + #let [rem (&;c.% (&;complex 3.0 5.0) + (&;complex 6.0 4.0))]] ($_ seq (assert "Adding 2 complex numbers is the same as adding their parts." (let [z (&;c.+ y x)] @@ -109,6 +111,17 @@ (assert "Scalar division is the inverse of scalar multiplication." (|> x (&;c.*' factor) (&;c./' factor) (within? margin-of-error x))) + + (assert "If you subtract the remainder, all divisions must be exact." + (let [rem (&;c.% y x) + quotient (|> x (&;c.- rem) (&;c./ y)) + floored (|> quotient + (update@ #&;real math;floor) + (update@ #&;imaginary math;floor)) + (^open "&/") &;Codec<Text,Complex>] + (within? 0.000000000001 + x + (|> quotient (&;c.* y) (&;c.+ rem))))) )) (test: "Conjugate, reciprocal, signum, negation" @@ -128,7 +141,7 @@ (|> x (&;c.* (&;reciprocal x)) (within? margin-of-error &;one))) (assert "Absolute value of signum is always sqrt(2), 1 or 0." - (let [signum-abs (|> x &;c.signum &;c.abs)] + (let [signum-abs (|> x &;c.signum &;c.abs (get@ #&;real))] (or (r.= 0.0 signum-abs) (r.= 1.0 signum-abs) (r.= (math;sqrt 2.0) signum-abs)))) @@ -140,8 +153,8 @@ (&;c.= back-again x)))) (assert "Negation doesn't change the absolute value." - (r.= (&;c.abs x) - (&;c.abs (&;c.negate x)))) + (r.= (get@ #&;real (&;c.abs x)) + (get@ #&;real (&;c.abs (&;c.negate x))))) )) ## ## Don't know how to test complex trigonometry properly. |