adding ConnectTest to automatically test connections

This commit is contained in:
Yotam Mann 2019-08-04 10:07:19 -04:00
parent dac194b8e2
commit e852b99a43
12 changed files with 32 additions and 62 deletions

View file

@ -1,6 +1,5 @@
import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { connectFrom } from "test/helper/Connect";
import { Noise } from "../../source/Noise";
import { Analyser } from "./Analyser";
@ -8,12 +7,6 @@ describe("Analyser", () => {
BasicTests(Analyser);
it("handles input connection", () => {
const anl = new Analyser();
connectFrom().connect(anl);
anl.dispose();
});
it("can get and set properties", () => {
const anl = new Analyser();
anl.set({

View file

@ -64,13 +64,6 @@ describe("AmplitudeEnvelope", () => {
context("Envelope", () => {
it("handles input and output connections", () => {
const ampEnv = new AmplitudeEnvelope();
connectFrom().connect(ampEnv);
ampEnv.connect(connectTo());
ampEnv.dispose();
});
it("extends envelope", () => {
const ampEnv = new AmplitudeEnvelope();
expect(ampEnv).to.be.instanceOf(Envelope);

View file

@ -10,12 +10,6 @@ describe("EQ3", () => {
context("EQing", () => {
it("handles input and output connections", () => {
const eq3 = new EQ3();
connectFrom().connect(eq3);
eq3.dispose();
});
it("can be constructed with an object", () => {
const eq3 = new EQ3({
high : -10,

View file

@ -12,12 +12,6 @@ describe("Filter", () => {
context("Filtering", () => {
it("handles input and output connections", () => {
const filter = new Filter();
connectFrom().connect(filter);
filter.dispose();
});
it("can be constructed with a arguments", () => {
const filter = new Filter(200, "highpass");
expect(filter.frequency.value).to.be.closeTo(200, 0.001);

View file

@ -10,13 +10,6 @@ describe("Abs", () => {
context("Absolute Value", () => {
it("handles input and output connections", () => {
const abs = new Abs();
connectFrom().connect(abs);
abs.connect(connectTo());
abs.dispose();
});
it("outputs the same value for positive values", () => {
return ConstantOutput(() => {
const signal = new Signal(0.4);

View file

@ -12,13 +12,6 @@ describe("AudioToGain", () => {
BasicTests(AudioToGain);
it("handles input and output connections", () => {
const a2g = new AudioToGain();
a2g.connect(connectTo());
connectFrom().connect(a2g);
a2g.dispose();
});
it("normalizes an oscillator to 0,1", () => {
return Offline(() => {
const osc = new Oscillator(1000).start();

View file

@ -11,13 +11,6 @@ describe("GainToAudio", () => {
context("Gain To Audio", () => {
it("handles input and output connections", () => {
const g2a = new GainToAudio();
connectFrom().connect(g2a);
g2a.connect(connectTo());
g2a.dispose();
});
it("outputs 0 for an input value of 0.5", () => {
return ConstantOutput(() => {
const sig = new Signal(0.5);

View file

@ -10,13 +10,6 @@ describe("Negate", () => {
context("Negating", () => {
it("handles input and output connections", () => {
const negate = new Negate();
connectFrom().connect(negate);
negate.connect(connectTo());
negate.dispose();
});
it("negateates a positive value", () => {
return ConstantOutput(() => {
const signal = new Signal(1);

View file

@ -13,10 +13,10 @@ describe("Signal", () => {
context("Signal Rate Value", () => {
it("handles input and output connections", () => {
it("has 1 input and 1 output", () => {
const signal = new Signal<number>();
connectFrom().connect(signal);
signal.connect(connectTo());
expect(signal.numberOfInputs).to.equal(1);
expect(signal.numberOfOutputs).to.equal(1);
signal.dispose();
});

View file

@ -1,5 +1,5 @@
import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { connectTo } from "test/helper/Connect";
import { ConstantOutput } from "test/helper/ConstantOutput";
import { Zero } from "./Zero";
@ -9,10 +9,11 @@ describe("Zero", () => {
context("Zero", () => {
it("handles output connections", () => {
const abs = new Zero();
abs.connect(connectTo());
abs.dispose();
it("has 0 inputs and 1 output", () => {
const zero = new Zero();
expect(zero.numberOfInputs).to.equal(0);
expect(zero.numberOfOutputs).to.equal(1);
zero.dispose();
});
it("always outputs 0", () => {

View file

@ -4,6 +4,7 @@ import "Tone/core/context/Destination";
import { OfflineContext } from "Tone/core/context/OfflineContext";
import { ToneWithContext } from "Tone/core/context/ToneWithContext";
import { Tone } from "Tone/core/Tone";
import { ConnectTest } from "./Connect";
export const testAudioContext = new OfflineContext(1, 1, 11025);
testAudioContext.initialize();
@ -47,5 +48,7 @@ export function BasicTests(Constr, ...args: any[]): void {
}
instance.dispose();
});
ConnectTest(Constr, ...args);
});
}

View file

@ -1,4 +1,5 @@
import { Gain } from "Tone/core/context/Gain";
import { ToneAudioNode } from "Tone/core/context/ToneAudioNode";
export function connectFrom(): Gain {
return new Gain();
@ -7,3 +8,22 @@ export function connectFrom(): Gain {
export function connectTo(): Gain {
return new Gain();
}
export function ConnectTest(constr, ...args: any[]): void {
it("handles input and output connections", () => {
const instance = new constr(...args);
// test each of the input and outputs and connect
if (instance.numberOfInputs) {
for (let input = 0; input < instance.numberOfInputs; input++) {
connectFrom().connect(instance, 0, input);
}
}
if (instance.numberOfOutputs) {
for (let output = 0; output < instance.numberOfOutputs; output++) {
instance.connect(connectTo(), output, 0);
}
}
instance.dispose();
});
}