Mercurial > hg > may
changeset 26:0d03455c105b
Pull out tests into subdir
author | Chris Cannam |
---|---|
date | Thu, 20 Dec 2012 21:56:27 +0000 |
parents | a6b1cc001232 |
children | 22880f531e5a |
files | block.yeti fvector.yeti syntheticstream.yeti test/test-framer.yeti test/test.yeti tests.yeti |
diffstat | 6 files changed, 152 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/block.yeti Thu Dec 20 15:25:46 2012 +0000 +++ b/block.yeti Thu Dec 20 21:56:27 2012 +0000 @@ -23,12 +23,14 @@ copyOf b = Block (vec.copyOf (unblock b)); -range b start len = - Block (vec.range (unblock b) start len); +rangeOf b start len = + Block (vec.rangeOf (unblock b) start len); resizedTo n b = Block (vec.resizedTo n (unblock b)); + + { zeros, ones, block, unblock, @@ -36,6 +38,6 @@ length = length', list = list', equal, -copyOf, range, resizedTo, +copyOf, rangeOf, resizedTo, }
--- a/fvector.yeti Thu Dec 20 15:25:46 2012 +0000 +++ b/fvector.yeti Thu Dec 20 21:56:27 2012 +0000 @@ -33,18 +33,26 @@ copyOf v is ~double[] -> ~double[] = Arrays#copyOf(v, list' v |> length); -range v start len is ~double[] -> number -> number -> ~double[] = +rangeOf v start len is ~double[] -> number -> number -> ~double[] = Arrays#copyOfRange(v, start, start + len); resizedTo n v is number -> ~double[] -> ~double[] = Arrays#copyOf(v, n); +concat v1 v2 is ~double[] -> ~double[] -> ~double[] = + (v1len = length' v1; + v2len = length' v2; + v = resizedTo (v1len + v2len) v1; + for [0..v2len-1] do i: v[v1len + i] := v2[i] done; + v); + { zeros, ones, vector, length = length', list = list', equal, -copyOf, range, resizedTo, +copyOf, rangeOf, resizedTo, +concat }
--- a/syntheticstream.yeti Thu Dec 20 15:25:46 2012 +0000 +++ b/syntheticstream.yeti Thu Dec 20 21:56:27 2012 +0000 @@ -35,7 +35,7 @@ rate, read count = (rc = min count (len - position); - result = vec.range data position rc; + result = vec.rangeOf data position rc; position := position + rc; block.block result), close = \(),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-framer.yeti Thu Dec 20 21:56:27 2012 +0000 @@ -0,0 +1,98 @@ + +program test_framer; + +fr = load framer; +block = load block; +test = load test.test; + +tests = [ + +"framecount-2x2": \( + fr = fr.frames 2 (test.testStream 2); + test.compare (length fr) 1 +), + +"framecount-2x3": \( + fr = fr.frames 2 (test.testStream 3); + test.compare (length fr) 2 +), + +"framecount-2x4": \( + fr = fr.frames 2 (test.testStream 4); + test.compare (length fr) 2 +), + +"framecount-2.1x0": \( + fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 0); + test.compare (length fr) 1 +), + +"framecount-2.1x1": \( + fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 1); + test.compare (length fr) 2 +), + +"framecount-2.1x2": \( + fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 2); + test.compare (length fr) 3 +), + +"framecount-2.1x3": \( + fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 3); + test.compare (length fr) 4 +), + +"framecount-4.1x4": \( + fr = fr.overlappingFrames { blocksize = 4, hop = 1 } (test.testStream 4); + test.compare (length fr) 7 +), + +"framecount-4.3x4": \( + fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (test.testStream 4); + test.compare (length fr) 2 +), + +"framecount-4.4x4": \( + fr = fr.overlappingFrames { blocksize = 4, hop = 4 } (test.testStream 4); + test.compare (length fr) 1 +), + +"framecount-3.2x4": \( + fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (test.testStream 4); + test.compare (length fr) 3 +), + +"frames-2x5": \( + fr = fr.frames 2 (test.testStream 5); + expected = array [ [1,2], [3,4], [5,0] ]; + obtained = array (map block.list fr); + test.compare obtained expected; +), + +"frames-4.3x4": \( + fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (test.testStream 4); + expected = array [ [0,1,2,3], [3,4,0,0] ]; + obtained = array (map block.list fr); + test.compare obtained expected; +), + +"frames-3.2x4": \( + fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (test.testStream 4); + expected = array [ [0,1,2], [2,3,4], [4,0,0] ]; + obtained = array (map block.list fr); + test.compare obtained expected; +), + +"frames-3.1x6": \( + fr = fr.overlappingFrames { blocksize = 3, hop = 1 } (test.testStream 6); + expected = array [ [0,0,1], [0,1,2], [1,2,3], [2,3,4], + [3,4,5], [4,5,6], [5,6,0], [6,0,0] ]; + obtained = array (map block.list fr); + test.compare obtained expected; +), + +]; + +test.runTests tests; + +();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test.yeti Thu Dec 20 21:56:27 2012 +0000 @@ -0,0 +1,38 @@ + +module test.test; + +vec = load fvector; +ss = load syntheticstream; + +testStream n is number -> 'a = ss.precalculated 1000 (vec.vector [1..n]); + +compare obtained expected = + if obtained == expected then + true; + else + println "** expected: \(expected)\n obtained: \(obtained)"; + false; + fi; + +select f = fold do r x: if f x then x::r else r fi done []; + +failedTests testHash = + select (!= "") + (mapHash do name f: + if f () then "" else + println "Test \(name) failed"; + name; + fi + done testHash); + +runTests testHash = + (failed = failedTests testHash; + println "\(length testHash - length failed)/\(length testHash) tests passed"; + if not empty? failed then + println "Failed tests [\(length failed)]: \(strJoin ' ' failed)"; + fi); + +{ + testStream, compare, failedTests, runTests +} +
--- a/tests.yeti Thu Dec 20 15:25:46 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ - -program tests; - -ss = load syntheticstream; -vec = load fvector; -fr = load framer; -block = load block; - -testStream n is number -> 'a = ss.precalculated 1000 (vec.vector [1..n]); - -compare obtained expected = - if obtained == expected then - true; - else - println "** expected: \(expected)\n obtained: \(obtained)"; - false; - fi; - -tests = [ - -"framecount-2x2": \( - fr = fr.frames 2 (testStream 2); - compare (length fr) 1 -), - -"framecount-2x3": \( - fr = fr.frames 2 (testStream 3); - compare (length fr) 2 -), - -"framecount-2x4": \( - fr = fr.frames 2 (testStream 4); - compare (length fr) 2 -), - -"framecount-2.1x0": \( - fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (testStream 0); - compare (length fr) 1 -), - -"framecount-2.1x1": \( - fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (testStream 1); - compare (length fr) 2 -), - -"framecount-2.1x2": \( - fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (testStream 2); - compare (length fr) 3 -), - -"framecount-2.1x3": \( - fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (testStream 3); - compare (length fr) 4 -), - -"framecount-4.1x4": \( - fr = fr.overlappingFrames { blocksize = 4, hop = 1 } (testStream 4); - compare (length fr) 7 -), - -"framecount-4.3x4": \( - fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (testStream 4); - compare (length fr) 2 -), - -"framecount-4.4x4": \( - fr = fr.overlappingFrames { blocksize = 4, hop = 4 } (testStream 4); - compare (length fr) 1 -), - -"framecount-3.2x4": \( - fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (testStream 4); - compare (length fr) 3 -), - -"frames-2x5": \( - fr = fr.frames 2 (testStream 5); - expected = array [ [1,2], [3,4], [5,0] ]; - obtained = array (map block.list fr); - compare obtained expected; -), - -"frames-4.3x4": \( - fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (testStream 4); - expected = array [ [0,1,2,3], [3,4,0,0] ]; - obtained = array (map block.list fr); - compare obtained expected; -), - -"frames-3.2x4": \( - fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (testStream 4); - expected = array [ [0,1,2], [2,3,4], [4,0,0] ]; - obtained = array (map block.list fr); - compare obtained expected; -), - -"frames-3.1x6": \( - fr = fr.overlappingFrames { blocksize = 3, hop = 1 } (testStream 6); - expected = array [ [0,0,1], [0,1,2], [1,2,3], [2,3,4], - [3,4,5], [4,5,6], [5,6,0], [6,0,0] ]; - obtained = array (map block.list fr); - compare obtained expected; -), - -]; - -var bad = 0; - -forHash tests do name f: - if not (f ()) then - println "\(name) failed."; - bad := bad + 1 - fi -done; - -total = length tests; -println "Testing done, \(total - bad)/\(total) OK.";