Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from khdkhd/acr/travis
Chore: Unit tests
- Loading branch information
Showing
7 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import test from 'ava' | ||
import sinon from 'sinon' | ||
import { Hat } from './hat' | ||
import { AudioContextMock } from '../mock/audio-context.mock' | ||
|
||
test('Hat factory returns object', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
t.true(typeof hat === 'object') | ||
}) | ||
|
||
test('Hat factory returns object with a duration getter and setter', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
hat.setDuration(1) | ||
t.is(1, hat.getDuration()) | ||
}) | ||
|
||
test('Hat connect method returns an object with a connect method', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
const nextInChain = { | ||
input: audioContext.createGain(), | ||
connect() {}, | ||
} | ||
t.true(typeof hat.connect(nextInChain).connect === 'function') | ||
}) | ||
|
||
test('Hat noteOn method call create oscillators in the audio context', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
hat.noteOn() | ||
t.true(audioContext.createOscillator.called) | ||
}) | ||
|
||
test('Hat noteOff method call stop on oscillator nodes', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
hat.noteOn() | ||
hat.noteOff() | ||
audioContext.getOscillatorNodes() | ||
.forEach((osc) => { | ||
t.true(osc.stop.called) | ||
}) | ||
}) | ||
|
||
test('Hat noteOff method cancel scheduled values on gain nodes', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const hat = Hat(audioContext) | ||
hat.noteOn() | ||
hat.noteOff() | ||
audioContext.getGainNodes() | ||
.forEach((gain) => { | ||
t.true(gain.gain.cancelScheduledValues.called) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import test from 'ava' | ||
import sinon from 'sinon' | ||
import { Kick } from './kick' | ||
import { AudioContextMock } from '../mock/audio-context.mock' | ||
|
||
test('Kick factory returns object', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
t.true(typeof kick === 'object') | ||
}) | ||
|
||
test('Kick factory returns object with a duration getter and setter', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.setDuration(1) | ||
t.is(1, kick.getDuration()) | ||
}) | ||
|
||
test('Kick factory returns object with a frequency getter and setter', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.setFrequency(440) | ||
t.is(440, kick.getFrequency()) | ||
}) | ||
|
||
test('Kick factory returns object with a finalFrequency getter and setter', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.setFinalFrequency(220) | ||
t.is(220, kick.getFinalFrequency()) | ||
}) | ||
|
||
test('Kick connect method returns an object with a connect method', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
const nextInChain = { | ||
input: audioContext.createGain(), | ||
connect() {}, | ||
} | ||
t.true(typeof kick.connect(nextInChain).connect === 'function') | ||
}) | ||
|
||
test('Kick noteOn method call create oscillators in the audio context', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.noteOn() | ||
t.true(audioContext.createOscillator.called) | ||
}) | ||
|
||
test('Kick noteOff method call stop on oscillator nodes', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.noteOn() | ||
kick.noteOff() | ||
audioContext.getOscillatorNodes() | ||
.forEach((osc) => { | ||
t.true(osc.stop.called) | ||
}) | ||
}) | ||
|
||
test('Kick noteOff method cancel scheduled values on osc gain nodes', (t) => { | ||
const audioContext = AudioContextMock(sinon.sandbox.create()) | ||
const kick = Kick(audioContext) | ||
kick.noteOn() | ||
kick.noteOff() | ||
let nG = 0 // number of gain nodes | ||
audioContext.getGainNodes() | ||
.forEach((gain) => { | ||
nG += gain.gain.cancelScheduledValues.called ? 1 : 0 | ||
}) | ||
t.is(audioContext.getGainNodes().length - 1, nG) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters