Skip to content

Commit 68014bd

Browse files
(Gsoc'21)➕Added tests for lnoise,pulse.js
1 parent 7099755 commit 68014bd

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

test/tests.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import('./tests/p5.PeakDetect.js');
44
import('./tests/p5.OnsetDetect.js');
55
import('./tests/p5.Distortion.js');
66
import('./tests/p5.AudioContext.js');
7-
import('./tests/p5.Looper.js')
7+
import('./tests/p5.Looper.js');
88
import('./tests/p5.Metro.js');
99
import('./tests/p5.Effect.js');
1010
import('./tests/p5.Filter.js');
@@ -20,6 +20,8 @@ import('./tests/p5.SoundRecorder.js');
2020
import('./tests/p5.SoundFile.js');
2121
import('./tests/p5.Amplitude.js');
2222
import('./tests/p5.Oscillator.js');
23+
import('./tests/p5.Pulse.js');
24+
import('./tests/p5.Noise.js');
2325
import('./tests/p5.Panner.js');
2426
import('./tests/p5.Panner3d.js');
2527
import('./tests/p5.Listener3d.js');

test/tests/p5.Noise.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const expect = chai.expect;
2+
3+
describe('p5.Noise', function () {
4+
it('can be created and disposed', function () {
5+
let noise = new p5.Noise();
6+
expect(noise).to.not.have.property('f');
7+
expect(noise).to.not.have.property('oscillator');
8+
expect(noise).to.have.property('buffer');
9+
expect(noise.started).to.be.false;
10+
expect(noise.buffer.type).to.equal('white');
11+
12+
noise.dispose();
13+
expect(noise.output).to.be.null;
14+
expect(noise.panner).to.be.null;
15+
expect(noise.buffer).to.be.null;
16+
expect(noise.noise).to.be.null;
17+
});
18+
describe('methods', function () {
19+
it('can get and set type', function (done) {
20+
let noise = new p5.Noise();
21+
noise.start();
22+
noise.setType('brown');
23+
expect(noise.getType()).to.equal('brown');
24+
noise.setType();
25+
expect(noise.getType()).to.equal('white');
26+
setTimeout(() => {
27+
expect(noise.started).to.be.true;
28+
done();
29+
}, 100);
30+
});
31+
it('can be started and stopped', function () {
32+
let noise = new p5.Noise();
33+
expect(noise).to.not.have.property('noise');
34+
noise.start();
35+
expect(noise).to.have.property('noise');
36+
expect(noise.noise).to.have.property('buffer');
37+
expect(noise.noise.loop).to.be.true;
38+
expect(noise.started).to.be.true;
39+
noise.stop();
40+
expect(noise.started).to.be.false;
41+
});
42+
//TODO: test noise buffer generator functions
43+
});
44+
});

test/tests/p5.Pulse.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)