changeset 170:5a1db7299a08

Add synthetic stream tests
author Chris Cannam
date Thu, 02 May 2013 11:27:20 +0100
parents fb0000d15b53
children df2383f6b99b
files yetilab/stream/syntheticstream.yeti yetilab/stream/test/test_syntheticstream.yeti yetilab/test/all.yeti
diffstat 3 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/stream/syntheticstream.yeti	Thu May 02 09:56:53 2013 +0100
+++ b/yetilab/stream/syntheticstream.yeti	Thu May 02 11:27:20 2013 +0100
@@ -27,7 +27,7 @@
     });
 
 sinusoid rate freq =
-    generated rate (sin . (* (freq / (2*pi * rate))));
+    generated rate (sin . (* (2 * pi * freq)));
 
 whiteNoise rate =
     generated rate \((Math#random() * 2.0) - 1.0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/stream/test/test_syntheticstream.yeti	Thu May 02 11:27:20 2013 +0100
@@ -0,0 +1,80 @@
+
+module yetilab.stream.test.test_syntheticstream;
+
+bl = load yetilab.block.block;
+mat = load yetilab.matrix.matrix;
+syn = load yetilab.stream.syntheticstream;
+
+{ compare, compareUsing } = load yetilab.test.test;
+
+compareApprox eps =
+    compareUsing do v1 v2: all id (map2 do f1 f2: abs (f1 - f2) < eps done v1 v2) done;
+
+epsilon = 0.000001;
+
+[
+
+"generated": \(
+    str = syn.generated 2 id;
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 2 and
+        compare str.available (Infinite ()) and
+        compare str.finished? false and
+        compare (bl.list ((str.read 4).getRow 0)) [ 0, 0.5, 1, 1.5 ] and
+        compare str.position 4
+),
+
+"sinusoid": \(
+    // 2Hz sine sampled 8 times a second
+    str = syn.sinusoid 8 2;
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 8 and
+        compare str.available (Infinite ()) and
+        compare str.finished? false and
+        compareApprox epsilon (bl.list ((str.read 6).getRow 0)) [ 0, 1, 0, -1, 0, 1 ] and
+        compare str.position 6
+),
+
+"silent": \(
+    str = syn.silent 8;
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 8 and
+        compare str.available (Infinite ()) and
+        compare str.finished? false and
+        compare (bl.list ((str.read 3).getRow 0)) [ 0, 0, 0 ] and
+        compare str.position 3
+),
+
+"precalculated-empty": \(
+    str = syn.precalculated 2 (bl.fromList []);
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 2 and
+        compare str.available (Known 0) and
+        compare str.finished? true and
+        compare (bl.list ((str.read 3).getRow 0)) [] and
+        compare str.position 0
+),
+
+"precalculated": \(
+    str = syn.precalculated 2 (bl.fromList [ 1, 2, 3, 4 ]);
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 2 and
+        compare str.available (Known 4) and
+        compare str.finished? false and
+        compare (bl.list ((str.read 3).getRow 0)) [ 1, 2, 3 ] and
+        compare str.position 3 and
+        compare str.available (Known 1) and
+        compare str.finished? false and
+        compare (bl.list ((str.read 3).getRow 0)) [ 4 ] and
+        compare str.position 4 and
+        compare str.available (Known 0) and
+        compare str.finished? true
+),
+
+] is hash<string, () -> boolean>
+
--- a/yetilab/test/all.yeti	Thu May 02 09:56:53 2013 +0100
+++ b/yetilab/test/all.yeti	Thu May 02 11:27:20 2013 +0100
@@ -10,6 +10,7 @@
 "framer"     : load yetilab.stream.test.test_framer,
 "channels"   : load yetilab.stream.test.test_channels,
 "audiofile"  : load yetilab.stream.test.test_audiofile,
+"synstream"  : load yetilab.stream.test.test_syntheticstream,
 "fft"        : load yetilab.transform.test.test_fft,
 "vamppost"   : load yetilab.vamp.test.test_vamppost,
 "vamp"       : load yetilab.vamp.test.test_vamp,