|
|
@@ -0,0 +1,38 @@ |
|
|
|
const expect = require('chai').expect; |
|
|
|
const sinon = require('sinon'); |
|
|
|
const Clock = require('../src/common/clock.js'); |
|
|
|
|
|
|
|
describe("Clock Tests", function(){ |
|
|
|
var count = 0; |
|
|
|
var tick = ()=>{count += 1;}; |
|
|
|
var clk = (new Clock()).clk(tick); |
|
|
|
|
|
|
|
function speedTest(hz){ |
|
|
|
let stime = (new Date()).getTime(); |
|
|
|
let dt = 0; |
|
|
|
clk.hz = hz; |
|
|
|
while (count < hz && dt < 1000){ |
|
|
|
clk.tick(); |
|
|
|
dt = ((new Date()).getTime()) - stime; |
|
|
|
} |
|
|
|
return dt; |
|
|
|
} |
|
|
|
|
|
|
|
it("4hz for approx. 1 second", function(){ |
|
|
|
let dt = speedTest(4); |
|
|
|
expect(count).to.equal(4); |
|
|
|
expect(dt).to.be.gt(750); |
|
|
|
}); |
|
|
|
|
|
|
|
it("4Khz for approx. 1 second", function(){ |
|
|
|
let dt = speedTest(4000); |
|
|
|
expect(count).to.be.lt(4004); |
|
|
|
expect(dt).to.be.lt(1000); |
|
|
|
}); |
|
|
|
|
|
|
|
it("4Mhz for approx. 1 second", function(){ |
|
|
|
let dt = speedTest(4000000); |
|
|
|
expect(count).to.be.lt(4000004); |
|
|
|
expect(dt).to.be.lt(1000); |
|
|
|
}); |
|
|
|
}); |