# HG changeset patch # User Chris Cannam # Date 1356104202 0 # Node ID e20d3c23a24307cb53c3619385366f3afc06bb06 # Parent 025c88d62f7a5a1f9468e70bd3f6c6099de7aeee Basic block maths functions, tests for same; simplify tests slightly diff -r 025c88d62f7a -r e20d3c23a243 blockfuncs.yeti --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/blockfuncs.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -0,0 +1,33 @@ + +module blockfuncs; + +b = load block; + +sum' = + sum . b.list; + +mean bl = + case b.length bl of + 0: 0; + len: sum' bl / len + esac; + +sqr = + b.fromList . (map do x: x*x done) . b.list; + +sqrt' = + b.fromList . (map sqrt) . b.list; + +rms = + sqrt . mean . sqr; + +{ +sum = sum', +mean, +sqr, +sqrt = sqrt', +rms +} + + + diff -r 025c88d62f7a -r e20d3c23a243 test/all.yeti --- a/test/all.yeti Fri Dec 21 13:32:03 2012 +0000 +++ b/test/all.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -4,8 +4,10 @@ test = load test.test; fr = load test.test_framer; vec = load test.test_fvector; +bf = load test.test_blockfuncs; test.runTests "fvector" vec.tests; test.runTests "framer" fr.tests; +test.runTests "blockfuncs" bf.tests; diff -r 025c88d62f7a -r e20d3c23a243 test/test.yeti --- a/test/test.yeti Fri Dec 21 13:32:03 2012 +0000 +++ b/test/test.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -32,7 +32,10 @@ println "\(group): Failed tests [\(length failed)]: \(strJoin ' ' failed)"; fi); +declare tests is hash boolean> -> 'a = + { tests }; + { - testStream, compare, failedTests, runTests + testStream, compare, failedTests, runTests, declare } diff -r 025c88d62f7a -r e20d3c23a243 test/test_blockfuncs.yeti --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_blockfuncs.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -0,0 +1,45 @@ + +module test.test_blockfuncs; + +stdSqrt = sqrt; + +{ zeros, ones, fromList, list } = load block; +{ sum, mean, sqr, sqrt, rms } = load blockfuncs; +{ declare, compare } = load test.test; + +declare [ + +"sum": \( + compare ((sum . zeros) 0) 0 and + compare ((sum . zeros) 5) 0 and + compare ((sum . ones) 5) 5 and + compare ((sum . fromList) [1,-2,3,0]) 2 +), + +"mean": \( + compare ((mean . zeros) 0) 0 and + compare ((mean . zeros) 5) 0 and + compare ((mean . ones) 5) 1 and + compare ((mean . fromList) [1,-2,3,0]) 0.5 +), + +"sqr": \( + compare ((list . sqr . zeros) 0) [] and + compare ((list . sqr . ones) 5) [1,1,1,1,1] and + compare ((list . sqr . fromList) [0.5,-2,3,0]) [0.25,4,9,0] +), + +"sqrt": \( + compare ((list . sqrt . zeros) 0) [] and + compare ((list . sqrt . ones) 5) [1,1,1,1,1] and + compare ((list . sqrt . fromList) [0.25,4,9,0]) [0.5,2,3,0] +), + +"rms": \( + compare ((rms . zeros) 0) 0 and + compare ((rms . ones) 5) 1 and + compare ((rms . fromList) [-1,2,2]) (stdSqrt 3) +), + +]; + diff -r 025c88d62f7a -r e20d3c23a243 test/test_framer.yeti --- a/test/test_framer.yeti Fri Dec 21 13:32:03 2012 +0000 +++ b/test/test_framer.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -5,7 +5,7 @@ block = load block; test = load test.test; -tests = [ +test.declare [ "framecount-2x2": \( fr = fr.frames { framesize = 2, hop = 2 } (test.testStream 2); @@ -89,6 +89,5 @@ ]; -{ tests is hash boolean> }; diff -r 025c88d62f7a -r e20d3c23a243 test/test_fvector.yeti --- a/test/test_fvector.yeti Fri Dec 21 13:32:03 2012 +0000 +++ b/test/test_fvector.yeti Fri Dec 21 15:36:42 2012 +0000 @@ -4,7 +4,7 @@ vec = load fvector; t = load test.test; -tests = [ +t.declare [ "zeros-empty": \( v = vec.zeros 0; @@ -100,5 +100,4 @@ ]; -{ tests is hash boolean> };