Skip to content

Commit eef4ce5

Browse files
(Gsoc'21)➕Added tests for audiocontext.js, Gain.js
1 parent 0490632 commit eef4ce5

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

test/tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import('./tests/main.js');
22
import('./tests/p5.Helpers.js');
33
import('./tests/p5.Distortion.js');
4+
import('./tests/p5.AudioContext.js');
45
import('./tests/p5.Effect.js');
56
import('./tests/p5.Filter.js');
7+
import('./tests/p5.Gain.js');
68
import('./tests/p5.FFT.js');
79
import('./tests/p5.Compressor.js');
810
import('./tests/p5.EQ.js');

test/tests/p5.AudioContext.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const expect = chai.expect;
2+
3+
describe('p5.AudioContext', function () {
4+
describe('getAudioContext', function () {
5+
it('returns a audioContext', function () {
6+
let audioContext = p5.prototype.getAudioContext();
7+
expect(audioContext).to.have.property('baseLatency').to.be.an('number');
8+
expect(audioContext).to.have.property('destination');
9+
expect(audioContext).to.have.property('state').to.be.an('string');
10+
});
11+
});
12+
13+
describe('userStartAudio', function () {
14+
it('can get initialized and returns a promise', function (done) {
15+
let startAudio = p5.prototype.userStartAudio();
16+
startAudio.then(() => {
17+
done();
18+
});
19+
});
20+
});
21+
});

test/tests/p5.Gain.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const expect = chai.expect;
2+
let gain;
3+
4+
describe('p5.Gain', function () {
5+
beforeEach(function () {
6+
gain = new p5.Gain();
7+
});
8+
9+
it('can be created', function () {
10+
expect(gain.input).to.have.property('gain');
11+
expect(gain.output).to.have.property('gain');
12+
let audioContext = gain.ac;
13+
expect(audioContext).to.have.property('baseLatency').to.be.an('number');
14+
expect(audioContext).to.have.property('destination');
15+
expect(audioContext).to.have.property('state').to.be.an('string');
16+
});
17+
it('can be created and disposed', function () {
18+
gain.dispose();
19+
expect(gain).to.not.have.property('input');
20+
expect(gain).to.not.have.property('output');
21+
});
22+
23+
describe('methods', function () {
24+
describe('setInput', function () {
25+
it('can set Input', function () {
26+
let soundFile = p5.prototype.loadSound('./testAudio/drum.mp3');
27+
gain.setInput(soundFile);
28+
});
29+
});
30+
describe('connect, disconnect', function () {
31+
it('can connect to empty node', function () {
32+
gain.connect();
33+
});
34+
it('can connect with or without input property', function () {
35+
let filter = new p5.Filter();
36+
gain.connect(filter);
37+
gain.connect(filter.input);
38+
});
39+
it('can disconnect', function () {
40+
let filter = new p5.Filter();
41+
gain.connect(filter);
42+
gain.disconnect();
43+
});
44+
});
45+
describe('amp', function () {
46+
it('can take only volume as input', function () {
47+
//TODO
48+
});
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)