Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for operators

  • Loading branch information...
commit 4ad95c9792f776864757b6513793674a3545bc5a 1 parent d87cd24
@oampo authored
View
27 tests/operators/Add.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testAdd() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var add = new Add(audiolet, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(add);
+ add.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ add.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0, 2);
+}
+
+test("Add", testAdd);
View
27 tests/operators/Divide.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testDivide() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var divide = new Divide(audiolet, 2);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(divide);
+ divide.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ divide.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -0.5, 0.5);
+}
+
+test("Divide", testDivide);
View
27 tests/operators/Modulo.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testModulo() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var modulo = new Modulo(audiolet, 0.1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(modulo);
+ modulo.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ modulo.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -0.1, 0.1);
+}
+
+test("Modulo", testModulo);
View
27 tests/operators/MulAdd.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testMulAdd() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var mulAdd = new MulAdd(audiolet, 0.5, 0.5);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(mulAdd);
+ mulAdd.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ mulAdd.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0, 1);
+}
+
+test("MulAdd", testMulAdd);
View
28 tests/operators/Multiply.js
@@ -0,0 +1,28 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testMultiply() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var multiply = new Multiply(audiolet, 2);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(multiply);
+ multiply.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ multiply.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer, 0.2);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -2, 2);
+ Assert.assertValuesReach(buffer, -1.9, 1.9);
+}
+
+test("Multiply", testMultiply);
View
30 tests/operators/Reciprocal.js
@@ -0,0 +1,30 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testReciprocal() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var mulAdd = new MulAdd(audiolet, 0.5, 1.5); // Values between 1 and 2
+ var reciprocal = new Reciprocal(audiolet, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(mulAdd);
+ mulAdd.connect(reciprocal);
+ reciprocal.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ mulAdd.tick();
+ reciprocal.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0.5, 1);
+}
+
+test("Reciprocal", testReciprocal);
View
27 tests/operators/Subtract.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testSubtract() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var subtract = new Subtract(audiolet, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(subtract);
+ subtract.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ subtract.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -2, 0);
+}
+
+test("Subtract", testSubtract);
View
27 tests/operators/Tanh.js
@@ -0,0 +1,27 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testTanh() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var tanh = new Tanh(audiolet, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(tanh);
+ tanh.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ tanh.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -0.8, 0.8); // Should be clipped
+}
+
+test("Tanh", testTanh);
Please sign in to comment.
Something went wrong with that request. Please try again.