|
| 1 | +const expect = chai.expect; |
| 2 | + |
| 3 | +describe('p5.Pulse', function () { |
| 4 | + it('can be created without any arguments', function () { |
| 5 | + let pulse = new p5.Pulse(); |
| 6 | + expect(pulse.w).to.be.zero; |
| 7 | + expect(pulse.oscillator.type).to.equal('sawtooth'); |
| 8 | + expect(pulse.f).to.equal(440); |
| 9 | + expect(pulse.osc2).to.have.property('connection'); |
| 10 | + expect(pulse.osc2).to.have.property('oscMods'); |
| 11 | + expect(pulse.osc2).to.have.property('oscillator'); |
| 12 | + expect(pulse.dcOffset).to.have.property('buffer'); |
| 13 | + expect(pulse.dcOffset).to.have.property('channelCount'); |
| 14 | + expect(pulse.dcGain).to.have.property('gain'); |
| 15 | + expect(pulse.output.gain.value).to.equal(1); |
| 16 | + }); |
| 17 | + it('can be with arguments', function () { |
| 18 | + let pulse = new p5.Pulse(220, 0.4); |
| 19 | + expect(pulse.w).to.equal(0.4); |
| 20 | + expect(pulse.f).to.equal(220); |
| 21 | + console.log(pulse); |
| 22 | + expect(pulse.dNode.delayTime.value).to.be.approximately(0.0009, 0.00001); |
| 23 | + expect(pulse.dcGain.gain.value).to.be.approximately(0.17, 0.001); |
| 24 | + }); |
| 25 | + describe('methods', function () { |
| 26 | + it('can set width', function (done) { |
| 27 | + let pulse = new p5.Pulse(); |
| 28 | + pulse.width(0.3); |
| 29 | + expect(pulse.dNode.delayTime.value).to.be.approximately(0.00068, 0.00001); |
| 30 | + expect(pulse.dcGain.gain.value).to.be.approximately(0.34, 0.001); |
| 31 | + |
| 32 | + //can take non-numerical value |
| 33 | + let osc = new p5.Oscillator(); |
| 34 | + pulse.width(osc); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + it('can be started and stopped', function (done) { |
| 38 | + let pulse = new p5.Pulse(444, 0.1); |
| 39 | + expect(pulse.started).to.be.false; |
| 40 | + pulse.start(221, 0.1); |
| 41 | + setTimeout(() => { |
| 42 | + expect(pulse.oscillator.frequency.value).to.equal(221); |
| 43 | + expect(pulse.oscillator.type).to.equal('sawtooth'); |
| 44 | + expect(pulse.osc2.oscillator.type).to.equal('sawtooth'); |
| 45 | + done(); |
| 46 | + }, 500); |
| 47 | + expect(pulse.started).to.be.true; |
| 48 | + expect(pulse.osc2.started).to.be.true; |
| 49 | + pulse.stop(221, 0.1); |
| 50 | + expect(pulse.started).to.be.false; |
| 51 | + expect(pulse.osc2.started).to.be.false; |
| 52 | + }); |
| 53 | + it('can set frequency', function () { |
| 54 | + //TODO |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments