Skip to content

Commit 0a659bf

Browse files
authored
Add test for helpers (#594)
1 parent 8fe9ab7 commit 0a659bf

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

test/tests.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import('./tests/p5.Master.js');
2+
import('./tests/p5.Helpers.js');
23
import('./tests/p5.Distortion.js');
34
import('./tests/p5.Effect.js');
45
import('./tests/p5.Filter.js');
@@ -10,6 +11,6 @@ import('./tests/p5.AudioVoice.js');
1011
import('./tests/p5.MonoSynth.js');
1112
import('./tests/p5.PolySynth.js');
1213
import('./tests/p5.SoundRecorder.js');
13-
import('./tests/p5.SoundFile.js')
14-
import('./tests/p5.Amplitude.js')
15-
import('./tests/p5.Oscillator.js')
14+
import('./tests/p5.SoundFile.js');
15+
import('./tests/p5.Amplitude.js');
16+
import('./tests/p5.Oscillator.js');

test/tests/p5.Helpers.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const expect = chai.expect;
2+
3+
describe('Testing helpers function', function () {
4+
it('p5.prototype.freqToMidi helper function', function () {
5+
const midi = p5.prototype.freqToMidi(880);
6+
expect(midi).to.equal(81);
7+
});
8+
9+
it('p5.prototype.midiToFreq helper function', function () {
10+
const freq = p5.prototype.midiToFreq(100);
11+
expect(freq).to.equal(2637.0204553029594);
12+
});
13+
14+
it('p5.prototype.noteToFreq helper function', function () {
15+
const freq = p5.prototype.noteToFreq('C4');
16+
expect(freq).to.equal(261.6255653005986);
17+
});
18+
19+
it('p5.prototype.soundFormats helper function', function () {
20+
// setting file format so that if we don't provide extension
21+
// our file will be loaded because _checkFileFormats add it for us.
22+
23+
p5.prototype.soundFormats('mp3');
24+
const file = p5.prototype._checkFileFormats('a');
25+
expect(file).to.be.equal('a.mp3');
26+
27+
// if we don't provide a valid sound format then soundFormats wil throw
28+
//error
29+
try {
30+
p5.prototype.soundFormats('ext');
31+
} catch (err) {
32+
expect(err).to.be.equal('ext is not a valid sound format!');
33+
}
34+
});
35+
});

0 commit comments

Comments
 (0)