2019-01-27 18:05:20 +00:00
|
|
|
import CtrlMarkov from "Tone/control/CtrlMarkov";
|
|
|
|
import Basic from "helper/Basic";
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
describe("CtrlMarkov", function(){
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Basic(CtrlMarkov);
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
context("API", function(){
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be constructed with a description and initial state", function(){
|
|
|
|
var markov = new CtrlMarkov({
|
|
|
|
"a" : ["a", "b"],
|
|
|
|
"b" : ["b", "c"],
|
|
|
|
"c" : "a"
|
|
|
|
}, "a");
|
|
|
|
expect(markov.values).to.have.keys(["a", "b", "c"]);
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
markov.dispose();
|
|
|
|
});
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can move to the next state", function(){
|
|
|
|
var markov = new CtrlMarkov({
|
|
|
|
"a" : "b",
|
|
|
|
"b" : "c",
|
|
|
|
"c" : "a"
|
|
|
|
}, "a");
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
expect(markov.next()).to.equal("b");
|
|
|
|
expect(markov.value).to.equal("b");
|
|
|
|
expect(markov.next()).to.equal("c");
|
|
|
|
expect(markov.next()).to.equal("a");
|
|
|
|
markov.dispose();
|
|
|
|
});
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can move to the next with an array of options", function(){
|
|
|
|
var markov = new CtrlMarkov({
|
|
|
|
"a" : ["b", "c"],
|
|
|
|
"b" : "a",
|
|
|
|
"c" : "a"
|
|
|
|
}, "a");
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
expect(markov.next()).to.satisfy(function(state){
|
|
|
|
return state === "b" || state === "c";
|
2015-11-04 00:14:15 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(markov.next()).to.equal("a");
|
|
|
|
markov.dispose();
|
|
|
|
});
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can move to the next with an object of options", function(){
|
|
|
|
var markov = new CtrlMarkov({
|
|
|
|
"a" : [{
|
|
|
|
"value" : "b",
|
|
|
|
"probability" : 0.2
|
|
|
|
}, {
|
|
|
|
"value" : "c",
|
|
|
|
"probability" : 0.9
|
|
|
|
}],
|
|
|
|
"b" : "a",
|
|
|
|
"c" : "a"
|
|
|
|
}, "a");
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
expect(markov.next()).to.satisfy(function(state){
|
|
|
|
return state === "b" || state === "c";
|
2015-11-04 00:14:15 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(markov.next()).to.equal("a");
|
|
|
|
markov.dispose();
|
|
|
|
});
|
2015-11-04 00:14:15 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("stays on a state when it has no more options", function(){
|
|
|
|
var markov = new CtrlMarkov({
|
|
|
|
"a" : "end"
|
|
|
|
}, "a");
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
expect(markov.next()).to.equal("end");
|
|
|
|
expect(markov.next()).to.equal("end");
|
|
|
|
markov.value = "a";
|
|
|
|
expect(markov.value).to.equal("a");
|
|
|
|
expect(markov.next()).to.equal("end");
|
|
|
|
expect(markov.next()).to.equal("end");
|
|
|
|
markov.dispose();
|
2015-11-04 00:14:15 +00:00
|
|
|
});
|
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|