Tone.js/test/control/CtrlRandom.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

import CtrlRandom from "Tone/control/CtrlRandom";
import Basic from "helper/Basic";
2015-11-04 00:14:15 +00:00
describe("CtrlRandom", function(){
2015-11-04 00:14:15 +00:00
Basic(CtrlRandom);
2015-11-04 00:14:15 +00:00
context("API", function(){
2015-11-04 00:14:15 +00:00
it("can be constructed with a min and max", function(){
var rando = new CtrlRandom(5, 10);
expect(rando.min).to.equal(5);
expect(rando.max).to.equal(10);
rando.dispose();
});
2015-11-04 00:14:15 +00:00
it("can be constructed with an options object", function(){
var rando = new CtrlRandom({
min : -10,
max : 100,
integer : true,
2015-11-04 00:14:15 +00:00
});
expect(rando.min).to.equal(-10);
expect(rando.max).to.equal(100);
expect(rando.integer).to.be.true;
rando.dispose();
});
2015-11-04 00:14:15 +00:00
it("returns numbers between min and max", function(){
var rando = new CtrlRandom({
min : 5,
max : 100,
2015-11-04 00:14:15 +00:00
});
for (var i = 0; i < 1000; i++){
expect(rando.value).to.be.within(5, 100);
}
rando.dispose();
});
2015-11-04 00:14:15 +00:00
it("returns integers between min and max", function(){
var rando = new CtrlRandom({
min : -10,
max : -2,
integer : true,
2015-11-04 00:14:15 +00:00
});
for (var i = 0; i < 1000; i++){
expect(rando.value).to.be.within(-10, -2);
expect(rando.value % 1).to.equal(0);
}
rando.dispose();
2015-11-04 00:14:15 +00:00
});
});
2017-12-30 16:26:29 +00:00
});