|
- 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 ts = 4000;
- let d = ts * 0.01;
- let dt = speedTest(ts);
- expect(count).to.be.gt(ts - d);
- expect(count).to.be.lt(ts + d);
- expect(dt).to.be.gt(990);
- expect(dt).to.be.lt(1010);
- });
-
- it("4Mhz for approx. 1 second", function(){
- let ts = 4000000;
- let d = ts * 0.01;
- let dt = speedTest(ts);
- expect(count).to.be.gt(ts - d);
- expect(count).to.be.lt(ts + d);
- expect(dt).to.be.gt(990);
- expect(dt).to.be.lt(1010);
- });
- });
|