Tone.js/test/signal/GreaterThan.js

89 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-10-26 04:48:51 +00:00
define(["helper/ConstantOutput", "helper/Basic", "Tone/signal/GreaterThan",
"Tone/signal/Signal", "Test"],
function (ConstantOutput, Basic, GreaterThan, Signal, Test) {
2015-08-24 21:29:19 +00:00
describe("GreaterThan", function(){
Basic(GreaterThan);
context("Comparison", function(){
it("handles input and output connections", function(){
var gt = new GreaterThan();
Test.connect(gt);
Test.connect(gt, 0);
Test.connect(gt, 1);
gt.connect(Test);
gt.dispose();
});
2017-02-20 21:40:41 +00:00
it("outputs 0 when signal is less than value", function(){
return ConstantOutput(function(){
var signal = new Signal(1);
var gt = new GreaterThan(20);
2015-08-24 21:29:19 +00:00
signal.connect(gt);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 0);
2015-08-24 21:29:19 +00:00
});
2017-10-26 04:48:51 +00:00
it("outputs 0 when signal is equal to the value", function(){
return ConstantOutput(function(){
var signal = new Signal(10);
var gt = new GreaterThan(10);
signal.connect(gt);
gt.toMaster();
}, 0);
});
2015-08-24 21:29:19 +00:00
2017-02-20 21:40:41 +00:00
it("outputs 1 value is greater than", function(){
return ConstantOutput(function(){
var signal = new Signal(0.8);
var gt = new GreaterThan(0.4);
2015-08-24 21:29:19 +00:00
signal.connect(gt);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 1);
2015-08-24 21:29:19 +00:00
});
2017-02-20 21:40:41 +00:00
it("can handle negative values", function(){
return ConstantOutput(function(){
var signal = new Signal(-2);
var gt = new GreaterThan(-4);
2015-08-24 21:29:19 +00:00
signal.connect(gt);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 1);
2015-08-24 21:29:19 +00:00
});
2017-02-20 21:40:41 +00:00
it("can set a new value", function(){
return ConstantOutput(function(){
var signal = new Signal(2);
var gt = new GreaterThan(-100);
2015-08-24 21:29:19 +00:00
gt.value = 1;
signal.connect(gt);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 1);
2015-08-24 21:29:19 +00:00
});
2017-02-20 21:40:41 +00:00
it("outputs 0 when first signal is less than second", function(){
return ConstantOutput(function(){
var sigA = new Signal(1);
var sigB = new Signal(4);
var gt = new GreaterThan();
2015-08-24 21:29:19 +00:00
sigA.connect(gt, 0, 0);
sigB.connect(gt, 0, 1);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 0);
2015-08-24 21:29:19 +00:00
});
2017-02-20 21:40:41 +00:00
it("outputs 1 when first signal is greater than second", function(){
return ConstantOutput(function(){
var sigA = new Signal(2.01);
var sigB = new Signal(2);
var gt = new GreaterThan();
2015-08-24 21:29:19 +00:00
sigA.connect(gt, 0, 0);
sigB.connect(gt, 0, 1);
2017-02-20 21:40:41 +00:00
gt.toMaster();
}, 1);
2015-08-24 21:29:19 +00:00
});
});
});
2017-10-26 04:48:51 +00:00
});