# HG changeset patch # User Chris Cannam # Date 1357662068 0 # Node ID d037211bf5d74ff18f94771183201e471bfa7049 # Parent 5f1996de9ef58c63a3af191f63a632df4c73b414 Further test tidying, add complex tests diff -r 5f1996de9ef5 -r d037211bf5d7 complex.yeti --- a/complex.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/complex.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -8,6 +8,10 @@ real, int getImag() imag, + double getMagnitude() + sqrt (real * real + imag * imag), + double getAngle() + Math#atan2(imag, real), String toString() if real == int real and imag == int imag then if imag < 0 then @@ -44,6 +48,12 @@ complex re im is number -> number -> ~Complex = new Complex(re, im); +magnitude c is ~Complex -> number = + c#getMagnitude(); + +angle c is ~Complex -> number = + c#getAngle(); + add c1 c2 is ~Complex -> ~Complex -> ~Complex = complex (real c1 + real c2) (imaginary c1 + imaginary c2); @@ -54,6 +64,8 @@ real, imaginary, complex, + magnitude, + angle, add, scale, i = complex 0 1, @@ -63,6 +75,8 @@ real is cplx -> number, imaginary is cplx -> number, complex is number -> number -> cplx, + magnitude is cplx -> number, + angle is cplx -> number, add is cplx -> cplx -> cplx, scale is number -> cplx -> cplx, i is cplx, diff -r 5f1996de9ef5 -r d037211bf5d7 test/all.yeti --- a/test/all.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/all.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -1,20 +1,17 @@ program test.all; -test = load test.test; -fr = load test.test_framer; -vec = load test.test_fvector; -bf = load test.test_blockfuncs; -fft = load test.test_fft; +{ runTests } = load test.test; tests = [ -"fvector": vec.tests, -"framer": fr.tests, -"blockfuncs": bf.tests, -"fft": fft.tests, +"fvector" : load test.test_fvector, +"framer" : load test.test_framer, +"blockfuncs" : load test.test_blockfuncs, +"complex" : load test.test_complex, +"fft" : load test.test_fft, ]; -bad = sum (mapHash do name tests: test.runTests name tests done tests); +bad = sum (mapHash do name testHash: runTests name testHash done tests); if (bad > 0) then println "\n** \(bad) test(s) failed!"; @@ -22,5 +19,3 @@ () fi - - diff -r 5f1996de9ef5 -r d037211bf5d7 test/test.yeti --- a/test/test.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/test.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -35,10 +35,7 @@ fi; bad); -declare tests is hash boolean> -> 'a = - { tests }; - { - testStream, compare, failedTests, runTests, declare + testStream, compare, failedTests, runTests } diff -r 5f1996de9ef5 -r d037211bf5d7 test/test_blockfuncs.yeti --- a/test/test_blockfuncs.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/test_blockfuncs.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -5,9 +5,9 @@ { zeros, consts, ones, fromList, list } = load block; { sum, mean, multiply, divideBy, sqr, sqrt, rms, fftshift, ifftshift } = load blockfuncs; -{ declare, compare } = load test.test; +{ compare } = load test.test; -declare [ +[ "sum": \( compare ((sum . zeros) 0) 0 and @@ -63,5 +63,6 @@ compare ((list . ifftshift . fromList) [4,5,1,2,3]) [1,2,3,4,5] ), -]; +] is hash boolean>; + diff -r 5f1996de9ef5 -r d037211bf5d7 test/test_complex.yeti --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_complex.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -0,0 +1,52 @@ +module test.test_complex; + +{ i, one, zero, real, imaginary, complex, magnitude, angle, add, scale } + = load complex; + +{ compare } = load test.test; + +[ + +"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) +), + +"constants": \( + compare (complex 0 1) i and + compare (complex 1 0) one and + compare (complex 0 0) zero +), + +] is hash boolean>; + + + diff -r 5f1996de9ef5 -r d037211bf5d7 test/test_fft.yeti --- a/test/test_fft.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/test_fft.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -5,14 +5,14 @@ { list, fromList } = load block; { complex } = load complex; -{ declare, compare } = load test.test; +{ compare } = load test.test; testFFT orig reals imags = (out = realForward (length orig) (fromList orig); back = realInverse (length orig) out; compare out (array (map2 complex reals imags)) and compare orig (list back)); -declare [ +[ "dc": \( testFFT [1,1,1,1] [4,0,0] [0,0,0]; @@ -41,6 +41,6 @@ testFFT [0,0,0,1] [1,0,-1] [0,1,0]; ), -]; +] is hash boolean>; diff -r 5f1996de9ef5 -r d037211bf5d7 test/test_framer.yeti --- a/test/test_framer.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/test_framer.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -3,91 +3,92 @@ fr = load framer; block = load block; -test = load test.test; -test.declare [ +{ compare, testStream } = load test.test; + +[ "framecount-2x2": \( - fr = fr.frames { framesize = 2, hop = 2 } (test.testStream 2); - test.compare (length fr) 1 + fr = fr.frames { framesize = 2, hop = 2 } (testStream 2); + compare (length fr) 1 ), "framecount-2x3": \( - fr = fr.frames { framesize = 2, hop = 2 } (test.testStream 3); - test.compare (length fr) 2 + fr = fr.frames { framesize = 2, hop = 2 } (testStream 3); + compare (length fr) 2 ), "framecount-2x4": \( - fr = fr.frames { framesize = 2, hop = 2 } (test.testStream 4); - test.compare (length fr) 2 + fr = fr.frames { framesize = 2, hop = 2 } (testStream 4); + compare (length fr) 2 ), "framecount-2.1x0": \( - fr = fr.frames { framesize = 2, hop = 1 } (test.testStream 0); - test.compare (length fr) 1 + fr = fr.frames { framesize = 2, hop = 1 } (testStream 0); + compare (length fr) 1 ), "framecount-2.1x1": \( - fr = fr.frames { framesize = 2, hop = 1 } (test.testStream 1); - test.compare (length fr) 2 + fr = fr.frames { framesize = 2, hop = 1 } (testStream 1); + compare (length fr) 2 ), "framecount-2.1x2": \( - fr = fr.frames { framesize = 2, hop = 1 } (test.testStream 2); - test.compare (length fr) 3 + fr = fr.frames { framesize = 2, hop = 1 } (testStream 2); + compare (length fr) 3 ), "framecount-2.1x3": \( - fr = fr.frames { framesize = 2, hop = 1 } (test.testStream 3); - test.compare (length fr) 4 + fr = fr.frames { framesize = 2, hop = 1 } (testStream 3); + compare (length fr) 4 ), "framecount-4.1x4": \( - fr = fr.frames { framesize = 4, hop = 1 } (test.testStream 4); - test.compare (length fr) 7 + fr = fr.frames { framesize = 4, hop = 1 } (testStream 4); + compare (length fr) 7 ), "framecount-4.3x4": \( - fr = fr.frames { framesize = 4, hop = 3 } (test.testStream 4); - test.compare (length fr) 2 + fr = fr.frames { framesize = 4, hop = 3 } (testStream 4); + compare (length fr) 2 ), "framecount-4.4x4": \( - fr = fr.frames { framesize = 4, hop = 4 } (test.testStream 4); - test.compare (length fr) 1 + fr = fr.frames { framesize = 4, hop = 4 } (testStream 4); + compare (length fr) 1 ), "framecount-3.2x4": \( - fr = fr.frames { framesize = 3, hop = 2 } (test.testStream 4); - test.compare (length fr) 3 + fr = fr.frames { framesize = 3, hop = 2 } (testStream 4); + compare (length fr) 3 ), "frames-2x5": \( - fr = fr.frames { framesize = 2, hop = 2 } (test.testStream 5); + fr = fr.frames { framesize = 2, hop = 2 } (testStream 5); expected = [ [1,2], [3,4], [5,0] ]; - test.compare (map block.list fr) expected; + compare (map block.list fr) expected; ), "frames-4.3x4": \( - fr = fr.frames { framesize = 4, hop = 3 } (test.testStream 4); + fr = fr.frames { framesize = 4, hop = 3 } (testStream 4); expected = [ [0,1,2,3], [3,4,0,0] ]; - test.compare (map block.list fr) expected; + compare (map block.list fr) expected; ), "frames-3.2x4": \( - fr = fr.frames { framesize = 3, hop = 2 } (test.testStream 4); + fr = fr.frames { framesize = 3, hop = 2 } (testStream 4); expected = [ [0,1,2], [2,3,4], [4,0,0] ]; - test.compare (map block.list fr) expected; + compare (map block.list fr) expected; ), "frames-3.1x6": \( - fr = fr.frames { framesize = 3, hop = 1 } (test.testStream 6); + fr = fr.frames { framesize = 3, hop = 1 } (testStream 6); expected = [ [0,0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,0], [6,0,0] ]; - test.compare (map block.list fr) expected; + compare (map block.list fr) expected; ), -]; +] is hash boolean>; diff -r 5f1996de9ef5 -r d037211bf5d7 test/test_fvector.yeti --- a/test/test_fvector.yeti Mon Jan 07 22:33:45 2013 +0000 +++ b/test/test_fvector.yeti Tue Jan 08 16:21:08 2013 +0000 @@ -2,61 +2,62 @@ module test.test_fvector; vec = load fvector; -t = load test.test; -t.declare [ +{ compare } = load test.test; + +[ "zeros-empty": \( v = vec.zeros 0; - t.compare (vec.length v) 0; + compare (vec.length v) 0; ), "zeros": \( v = vec.zeros 3; - t.compare (vec.length v) 3 and - t.compare v[0] 0 and - t.compare v[1] 0 and - t.compare v[2] 0; + compare (vec.length v) 3 and + compare v[0] 0 and + compare v[1] 0 and + compare v[2] 0; ), "consts-empty": \( v = vec.consts 4 0; - t.compare (vec.length v) 0; + compare (vec.length v) 0; ), "consts": \( v = vec.consts 4 3; - t.compare (vec.length v) 3 and - t.compare v[0] 4 and - t.compare v[1] 4 and - t.compare v[2] 4; + compare (vec.length v) 3 and + compare v[0] 4 and + compare v[1] 4 and + compare v[2] 4; ), "ones-empty": \( v = vec.ones 0; - t.compare (vec.length v) 0; + compare (vec.length v) 0; ), "ones": \( v = vec.ones 3; - t.compare (vec.length v) 3 and - t.compare v[0] 1 and - t.compare v[1] 1 and - t.compare v[2] 1; + compare (vec.length v) 3 and + compare v[0] 1 and + compare v[1] 1 and + compare v[2] 1; ), "from-list-empty": \( v = vec.vector []; - t.compare (vec.length v) 0; + compare (vec.length v) 0; ), "from-list": \( v = vec.vector [1,2,3,4]; - t.compare (vec.length v) 4 and - t.compare v[0] 1 and - t.compare v[1] 2 and - t.compare v[2] 3 and - t.compare v[3] 4; + compare (vec.length v) 4 and + compare v[0] 1 and + compare v[1] 2 and + compare v[2] 3 and + compare v[3] 4; ), "equal-empty": \( @@ -119,6 +120,7 @@ vec.equal (vec.concat [v,w,v]) (vec.vector [1,2,3,4,5,6,1,2,3]) ), -]; +] is hash boolean>; + diff -r 5f1996de9ef5 -r d037211bf5d7 yc --- a/yc Mon Jan 07 22:33:45 2013 +0000 +++ b/yc Tue Jan 08 16:21:08 2013 +0000 @@ -1,3 +1,3 @@ #!/bin/sh -YETI_LIBDIR=/usr/local/lib/yeti +YETI_LIBDIR=../yeti rlwrap $JAVA_HOME/bin/java -classpath $YETI_LIBDIR/yeti.jar:$YETI_LIBDIR/yeti-lib.jar:jtransforms-2.4.jar yeti.lang.compiler.yeti "$@"