Mercurial > hg > may
view src/may/stream/test/test_framer.yeti @ 504:1b981d57d90f redo_framer
Fix and tests for non-padded framer mode
author | Chris Cannam |
---|---|
date | Wed, 20 Nov 2013 10:14:08 +0000 |
parents | 28fb7e461b31 |
children | 38e7dce5fa37 |
line wrap: on
line source
module may.stream.test.test_framer; fr = load may.stream.framer; vec = load may.vector; mat = load may.matrix; syn = load may.stream.syntheticstream; { compare, compareUsing } = load may.test.test; rate = 10; testStream n is number -> 'a = syn.precalculatedMono rate (vec.fromList [1..n]); compareFrames frames1 frames2 = all id (map2 do f1 f2: compareUsing mat.equal f1 f2 done frames1 (map (mat.newRowVector . vec.fromList) frames2)); testFramesWith framesize opts length expected firstChunkSize = (f = fr.frames framesize opts (testStream length); str = fr.streamed rate framesize opts f; ts = testStream length; // newly initialised stream compareFrames f expected and (firstChunk = str.read firstChunkSize; compareUsing mat.equal firstChunk (ts.read firstChunkSize)) and compare str.position firstChunkSize and compare str.finished? false and (restChunk = str.read (length - firstChunkSize); compareUsing mat.equal restChunk (ts.read (length - firstChunkSize))) and compare str.position length and (trailingZeros = str.read (framesize + 1); compareUsing mat.equal trailingZeros (mat.zeroMatrix { rows = str.channels, columns = mat.width trailingZeros }) and (mat.width trailingZeros < framesize)) and compare str.finished? true and compare str.available (Known 0)); testFramesInvertible framesize opts length expected = all id (map (testFramesWith framesize opts length expected) [1..length]); testFrames framesize opts length expected = (f = fr.frames framesize opts (testStream length); compareFrames f expected); [ "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-2x2b": \( fr = fr.frames 2 [ Hop 2 ] (testStream 2); compare (length fr) 1 ), "framecount-2x3b": \( fr = fr.frames 2 [ Hop 2 ] (testStream 3); compare (length fr) 2 ), "framecount-2x4b": \( fr = fr.frames 2 [ Hop 2 ] (testStream 4); compare (length fr) 2 ), "framecount-2.1x0": \( fr = fr.frames 2 [ Hop 1 ] (testStream 0); compare (length fr) 1 ), "framecount-2.1x1": \( fr = fr.frames 2 [ Hop 1 ] (testStream 1); compare (length fr) 2 ), "framecount-2.1x2": \( fr = fr.frames 2 [ Hop 1 ] (testStream 2); compare (length fr) 3 ), "framecount-2.1x3": \( fr = fr.frames 2 [ Hop 1 ] (testStream 3); compare (length fr) 4 ), "framecount-4.1x4": \( fr = fr.frames 4 [ Hop 1 ] (testStream 4); compare (length fr) 7 ), "framecount-4.3x4": \( fr = fr.frames 4 [ Hop 3 ] (testStream 4); compare (length fr) 2 ), "framecount-4.4x4": \( fr = fr.frames 4 [ Hop 4 ] (testStream 4); compare (length fr) 1 ), "framecount-3.2x4": \( fr = fr.frames 3 [ Hop 2 ] (testStream 4); compare (length fr) 3 ), "frames-2x5": \( testFramesInvertible 2 [ Hop 2 ] 5 [ [1,2], [3,4], [5,0] ]; ), "frames-4.3x4": \( testFrames 4 [ Hop 3 ] 4 [ [0,1,2,3], [3,4,0,0] ]; ), "frames-3.2x4": \( testFrames 3 [ Hop 2 ] 4 [ [0,1,2], [2,3,4], [4,0,0] ]; ), "frames-4.3x4np": \( testFrames 4 [ Hop 3, Padded false ] 4 [ [1,2,3,4], [4,0,0,0] ]; ), "frames-3.2x4np": \( testFrames 3 [ Hop 2, Padded false ] 4 [ [1,2,3], [3,4,0], [0,0,0] ]; ), "frames-3.1x6": \( testFramesInvertible 3 [ Hop 1 ] 6 [ [0,0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,0], [6,0,0] ]; ), "frames-4.2x8": \( testFramesInvertible 4 [ Hop 2 ] 8 [ [0,0,1,2], [1,2,3,4], [3,4,5,6], [5,6,7,8], [7,8,0,0] ]; ), "overlapAdd-3.1": \( compareUsing (mat.equal) (fr.overlapAdd 2 [ mat.newRowVector (vec.fromList [ 1,2,3 ]), mat.newRowVector (vec.fromList [ 4,5,6 ]), mat.newRowVector (vec.fromList [ 7,8,9 ]) ]) (mat.newRowVector (vec.fromList [ 1,6,15,14,9 ])) ), "overlapAdd-3.2": \( compareUsing (mat.equal) (fr.overlapAdd 1 [ mat.newRowVector (vec.fromList [ 1,2,3 ]), mat.newRowVector (vec.fromList [ 4,5,6 ]), mat.newRowVector (vec.fromList [ 7,8,9 ]) ]) (mat.newRowVector (vec.fromList [ 1,2,7,5,13,8,9 ])) ), "overlapAdd-4.2": \( compareUsing (mat.equal) (fr.overlapAdd 2 [ mat.newRowVector (vec.fromList [ 1,2,3,4 ]), mat.newRowVector (vec.fromList [ 5,6,7,8 ]), mat.newRowVector (vec.fromList [ 9,0,1,2 ]) ]) (mat.newRowVector (vec.fromList [ 1,2,8,10,16,8,1,2 ])) ), "overlapAdd-6+4.2": \( // Must work even if blocks vary in length (what if shorter than // overlap though?) compareUsing (mat.equal) (fr.overlapAdd 2 [ mat.newRowVector (vec.fromList [ 1,2,3,4,5,6 ]), mat.newRowVector (vec.fromList [ 7,8,9,0 ]), mat.newRowVector (vec.fromList [ 1,2,3 ]), mat.newRowVector (vec.fromList [ 4,5,6 ]) ]) (mat.newRowVector (vec.fromList [ 1,2,3,4,12,14,10,6,8,6 ])) ), ] is hash<string, () -> boolean>;