Mercurial > hg > may
changeset 27:22880f531e5a
Implement concat, add fvector tests
author | Chris Cannam |
---|---|
date | Thu, 20 Dec 2012 23:04:52 +0000 |
parents | 0d03455c105b |
children | 7c1f0996b1f7 |
files | block.yeti fvector.yeti test/all.yeti test/test-framer.yeti test/test.yeti test/test_framer.yeti test/test_fvector.yeti |
diffstat | 7 files changed, 220 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/block.yeti Thu Dec 20 21:56:27 2012 +0000 +++ b/block.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -29,7 +29,8 @@ resizedTo n b = Block (vec.resizedTo n (unblock b)); - +concat b1 b2 = + Block (vec.concat (unblock b1) (unblock b2)); { zeros, ones, @@ -39,5 +40,7 @@ list = list', equal, copyOf, rangeOf, resizedTo, +concat, } +
--- a/fvector.yeti Thu Dec 20 21:56:27 2012 +0000 +++ b/fvector.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -53,6 +53,6 @@ list = list', equal, copyOf, rangeOf, resizedTo, -concat +concat, }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/all.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -0,0 +1,11 @@ + +program test.all_tests; + +test = load test.test; +fr = load test.test_framer; +vec = load test.test_fvector; + +test.runTests "fvector" vec.tests; +test.runTests "framer" fr.tests; + +
--- a/test/test-framer.yeti Thu Dec 20 21:56:27 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ - -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; - -();
--- a/test/test.yeti Thu Dec 20 21:56:27 2012 +0000 +++ b/test/test.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -25,11 +25,11 @@ fi done testHash); -runTests testHash = +runTests group testHash = (failed = failedTests testHash; - println "\(length testHash - length failed)/\(length testHash) tests passed"; + println "\(group): \(length testHash - length failed)/\(length testHash) tests passed"; if not empty? failed then - println "Failed tests [\(length failed)]: \(strJoin ' ' failed)"; + println "\(group): Failed tests [\(length failed)]: \(strJoin ' ' failed)"; fi); {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_framer.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -0,0 +1,98 @@ + +module test.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; +), + +]; + +{ tests is hash<string, () -> boolean> }; + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_fvector.yeti Thu Dec 20 23:04:52 2012 +0000 @@ -0,0 +1,103 @@ + +module test.test_fvector; + +vec = load fvector; +t = load test.test; + +{ +tests = [ + +"zeros-empty": \( + v = vec.zeros 0; + t.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; +), + +"ones-empty": \( + v = vec.ones 0; + t.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; +), + +"from-list-empty": \( + v = vec.vector []; + t.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; +), + +"equal-empty": \( + vec.equal (vec.vector []) (vec.vector []) +), + +"equal": \( + v = vec.vector [1,1,1,1]; + w = vec.ones 4; + w' = vec.zeros 4; + w'' = vec.ones 3; + vec.equal v w and not vec.equal v w' and not vec.equal v w''; +), + +"copyOf-empty": \( + vec.equal (vec.vector []) (vec.copyOf (vec.vector [])) +), + +"copyOf": \( + v = vec.vector [1,2,3,4]; + w = vec.copyOf v; + vec.equal v w and ( + v[0] := 0; // check result is not aliasing inputs + not vec.equal v w + ); +), + +"rangeOf": \( + v = vec.vector [1,2,3,4]; + vec.equal (vec.rangeOf v 0 4) v and ( + vec.equal (vec.rangeOf v 2 2) (vec.vector [3,4]) + ) +), + +"resizedTo": \( + vec.equal (vec.resizedTo 4 (vec.vector [])) (vec.zeros 4) and + vec.equal (vec.resizedTo 2 (vec.vector [1,2])) (vec.vector [1,2]) and + vec.equal (vec.resizedTo 3 (vec.vector [1,2])) (vec.vector [1,2,0]) and + vec.equal (vec.resizedTo 2 (vec.vector [1,2,3])) (vec.vector [1,2]); +), + +"concat": \( + v = vec.vector [1,2,3]; + w = vec.vector [4,5,6]; + x = vec.concat v w; + x' = vec.vector [1,2,3,4,5,6]; + vec.equal x x' and + (v[0] := 0; // check result is not aliasing inputs + w[0] := 0; + vec.equal x x') and + vec.equal x' (vec.concat x' (vec.vector [])) and + vec.equal x' (vec.concat (vec.vector []) x') +), + +] is hash<string, () -> boolean> }; +