-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fft tests for smoothing and bins (#185)
- Loading branch information
1 parent
90918a3
commit 9788312
Showing
3 changed files
with
74 additions
and
12 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
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,62 @@ | ||
define(['chai'], | ||
function(chai) { | ||
|
||
var expect = chai.expect; | ||
|
||
describe('p5.FFT', function() { | ||
var fft; | ||
|
||
beforeEach(function() { | ||
fft = new p5.FFT(); | ||
}); | ||
|
||
afterEach(function() { | ||
fft.dispose(); | ||
}); | ||
|
||
it('has default bins of 1024', function() { | ||
expect(fft.bins).to.equal(1024); | ||
}); | ||
|
||
it('has default smoothing of 0.8', function() { | ||
expect(fft.smooth()).to.equal(0.8); | ||
expect(fft.smoothing).to.equal(0.8); | ||
}); | ||
|
||
it('accepts smoothing and bins as args', function() { | ||
fft.dispose(); | ||
fft = new p5.FFT(0, 128); | ||
expect(fft.smoothing).to.equal(0); | ||
expect(fft.bins).to.equal(128); | ||
}); | ||
|
||
it('can set smoothing to zero', function() { | ||
fft.smooth(0); | ||
expect(fft.smoothing).to.equal(0); | ||
expect(fft.smooth()).to.equal(0); | ||
fft.smooth(0.9); | ||
expect(fft.smoothing).to.equal(0.9); | ||
expect(fft.smooth()).to.equal(0.9); | ||
}); | ||
|
||
it('handles smoothing values out of range', function() { | ||
expect(fft.smooth()).to.equal(0.8); | ||
try { | ||
fft.smooth(-1); | ||
expect.fail(); | ||
} catch(e) { | ||
expect(e).to.be.an.instanceof(Error); | ||
} | ||
expect(fft.smoothing).to.equal(0.8); | ||
expect(fft.smooth()).to.equal(0.8); | ||
try { | ||
fft.smooth('some bad param'); | ||
expect.fail(); | ||
} catch(e) { | ||
expect(e).to.be.an.instanceof(Error); | ||
} | ||
expect(fft.smoothing).to.equal(0.8); | ||
expect(fft.smooth()).to.equal(0.8); | ||
}); | ||
}); | ||
}); |