view yetilab/vector/test/test_complex.yeti @ 222:77c6a81c577f matrix_opaque_immutable

Move block directory -> vector
author Chris Cannam
date Sat, 11 May 2013 15:58:36 +0100
parents yetilab/block/test/test_complex.yeti@a7f4eb1cdd72
children 197d23954a4e
line wrap: on
line source
module yetilab.vector.test.test_complex;

{ real, imaginary, complex, magnitude, angle, add, scale, zeros, magnitudes, angles }
   = load yetilab.vector.complex;

{ compare } = load yetilab.test.test;

vec = load yetilab.vector.vector;

[

"complex": \( 
    compare (complex 1 2) (complex 1 2) and
        complex (-1) 2 != complex 1 2
),

"real": \(
    compare (real (complex 3 2)) 3
),

"imaginary": \(
    compare (imaginary (complex 3 4)) 4
),

"magnitude": \(
    compare (magnitude (complex (-3) 4)) 5
),

"angle": \(
    compare (angle (complex 1 0)) 0 and
        compare (angle (complex 1 1)) (pi/4) and
        compare (angle (complex 0 1)) (pi/2) and
        compare (angle (complex (-1) 0)) pi and
        compare (angle (complex 0 (-1))) (-pi/2)
),

"add": \(
    compare (add (complex 2 3) (complex (-4) 5)) (complex (-2) 8)
),

"scale": \(
    compare (scale 4 (complex 2 3)) (complex 8 12)
),

"zeros": \(
    compare (zeros 0) (array []) and
        compare (zeros 3) (array [complex 0 0, complex 0 0, complex 0 0])
),

"magnitudes": \(
    compare (vec.list (magnitudes [ complex (-3) 4, complex 4 3, complex 0 0 ]))
            [ 5, 5, 0 ] and
       compare (vec.list (magnitudes (array []))) []
),

"angles": \(
    compare (vec.list (angles [ complex 1 0, complex (-1) 0, complex 0 (-1) ]))
            [ 0, pi, -pi/2 ] and
       compare (vec.list (angles (array []))) []
),


] is hash<string, () -> boolean>;