Tone.js/test/core/TimelineState.js

82 lines
2.8 KiB
JavaScript
Raw Normal View History

define(["Test", "Tone/core/TimelineState"], function(Test, TimelineState) {
2015-08-17 02:21:14 +00:00
2015-08-18 20:31:12 +00:00
describe("TimelineState", function(){
2015-08-17 02:21:14 +00:00
2017-12-30 16:26:29 +00:00
it("can be created and disposed", function(){
2015-08-18 20:31:12 +00:00
var sched = new TimelineState();
2015-08-17 02:21:14 +00:00
sched.dispose();
Test.wasDisposed(sched);
});
2017-12-30 16:26:29 +00:00
it("can schedule a state at a given time", function(){
2015-08-18 20:31:12 +00:00
var sched = new TimelineState();
2015-08-17 02:21:14 +00:00
sched.setStateAtTime("A", 0);
sched.setStateAtTime("B", 1);
sched.setStateAtTime("C", 1);
sched.dispose();
});
2017-12-30 16:26:29 +00:00
it("can get a state at a given time", function(){
2015-08-18 20:31:12 +00:00
var sched = new TimelineState();
2015-08-17 02:21:14 +00:00
sched.setStateAtTime("A", 0);
sched.setStateAtTime("B", 1);
sched.setStateAtTime("C", 2);
2016-12-19 03:14:14 +00:00
expect(sched.getValueAtTime(1)).to.equal("B");
expect(sched.getValueAtTime(0.999)).to.equal("A");
2015-08-17 02:21:14 +00:00
sched.dispose();
});
2017-12-30 16:26:29 +00:00
it("returns undefined if it's before any scheduled states", function(){
2015-08-18 20:31:12 +00:00
var sched = new TimelineState();
2015-08-17 02:21:14 +00:00
sched.setStateAtTime("A", 0);
sched.setStateAtTime("B", 1);
sched.setStateAtTime("C", 2);
2016-12-19 03:14:14 +00:00
expect(sched.getValueAtTime(-11)).is.undefined;
2015-08-17 02:21:14 +00:00
sched.dispose();
});
2017-12-30 16:26:29 +00:00
it("returns initial state if defined and query time is before any scheduled states", function(){
2015-08-18 20:31:12 +00:00
var sched = new TimelineState("initial");
2015-08-17 02:21:14 +00:00
sched.setStateAtTime("A", 20);
sched.setStateAtTime("B", 21);
sched.setStateAtTime("C", 22);
2016-12-19 03:14:14 +00:00
expect(sched.getValueAtTime(0)).is.equal("initial");
2015-08-17 02:21:14 +00:00
sched.dispose();
});
it("gets the last occurance of the state at or before the given time", function(){
var sched = new TimelineState();
sched.setStateAtTime("A", 0);
sched.setStateAtTime("B", 1);
sched.setStateAtTime("C", 2);
sched.setStateAtTime("B", 3);
expect(sched.getLastState("B", 1)).exists;
expect(sched.getLastState("B", 1).state).is.equal("B");
expect(sched.getLastState("B", 2)).exists;
expect(sched.getLastState("B", 2).state).is.equal("B");
expect(sched.getLastState("B", 2).time).is.equal(1);
expect(sched.getLastState("B", 0.9)).not.exists;
expect(sched.getLastState("B", 4).state).is.equal("B");
expect(sched.getLastState("B", 4).time).is.equal(3);
sched.dispose();
});
2015-08-17 02:21:14 +00:00
it("gets the next occurance of the state at or before the given time", function(){
var sched = new TimelineState();
sched.setStateAtTime("A", 0);
sched.setStateAtTime("B", 1);
sched.setStateAtTime("C", 2);
sched.setStateAtTime("B", 3);
expect(sched.getNextState("B", 1)).exists;
expect(sched.getNextState("B", 1).state).is.equal("B");
expect(sched.getNextState("B", 2)).exists;
expect(sched.getNextState("B", 2).state).is.equal("B");
expect(sched.getNextState("B", 2).time).is.equal(3);
expect(sched.getNextState("B", 0.9)).exists;
expect(sched.getNextState("B", 0.9).state).is.equal("B");
expect(sched.getNextState("B", 0.9).time).is.equal(1);
sched.dispose();
});
2015-08-17 02:21:14 +00:00
});
2017-12-30 16:26:29 +00:00
});