Tone.js/Tone/source/oscillator/PWMOscillator.test.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-07-16 21:10:07 +00:00
import { expect } from "chai";
2024-05-03 14:10:40 +00:00
import { BasicTests } from "../../../test/helper/Basic.js";
import { CompareToFile } from "../../../test/helper/CompareToFile.js";
import { connectFrom } from "../../../test/helper/Connect.js";
import { OscillatorTests } from "../../../test/helper/OscillatorTests.js";
import { SourceTests } from "../../../test/helper/SourceTests.js";
import { PWMOscillator } from "./PWMOscillator.js";
2019-07-16 21:10:07 +00:00
describe("PWMOscillator", () => {
// run the common tests
BasicTests(PWMOscillator);
SourceTests(PWMOscillator);
OscillatorTests(PWMOscillator);
it("matches a file", () => {
return CompareToFile(() => {
const osc = new PWMOscillator().toDestination();
2019-07-16 21:10:07 +00:00
osc.start(0.1);
2019-07-16 21:15:55 +00:00
}, "pwmOscillator.wav", 0.01);
2019-07-16 21:10:07 +00:00
});
context("Modulation Frequency", () => {
it("can set the modulation frequency", () => {
const pwm = new PWMOscillator();
pwm.modulationFrequency.value = 0.2;
expect(pwm.modulationFrequency.value).to.be.closeTo(0.2, 0.001);
pwm.dispose();
});
it("can connect a signal to the modulationFrequency", () => {
const pwm = new PWMOscillator();
connectFrom().connect(pwm.modulationFrequency);
pwm.dispose();
});
});
context("Types", () => {
it("reports it's type", () => {
const osc = new PWMOscillator();
expect(osc.type).to.equal("pwm");
expect(osc.baseType).to.equal("pwm");
expect(osc.partials).to.deep.equal([]);
osc.dispose();
});
});
});