Add tests for IOUtils

This commit is contained in:
Andrew Stewart 2014-10-15 15:54:13 -07:00
parent 4e8e65ddea
commit 1f36d5a030
1 changed files with 24 additions and 0 deletions

24
test/specs/io/utils.js Normal file
View File

@ -0,0 +1,24 @@
"use strict";
var Utils = source('io/utils.js');
describe("IOUtils", function() {
describe("#periodAndDuty", function() {
var fn = Utils.periodAndDuty;
it("calculates values for PWM", function() {
var value = fn(0.5, 2000, null, null);
expect(value).to.be.eql({ period: 500000, duty: 250000 })
});
it("calculates values for servos", function() {
var value = fn(0.5, 50, { min: 500, max: 2400 }, 'high');
expect(value).to.be.eql({ duty: 1450000, period: 20000000 })
});
it("calculates values for different polarities", function() {
var value = fn(0.5, 50, { min: 500, max: 2400 }, 'low');
expect(value).to.be.eql({ duty: 18550000, period: 20000000 })
});
});
});