Browse Source

Clock tests updated for new features.

master
Bryan Miller 5 years ago
parent
commit
1309eca595
1 changed files with 32 additions and 5 deletions
  1. +32
    -5
      test/unit.src.clock.spec.js

+ 32
- 5
test/unit.src.clock.spec.js View File



describe("Clock Tests", function(){ describe("Clock Tests", function(){
var count = 0; var count = 0;
var count2 = 0;
var tick = ()=>{count += 1;}; var tick = ()=>{count += 1;};
var tick2 = () =>{count2 += 1;};
var clk = (new Clock()).clk(tick); var clk = (new Clock()).clk(tick);
var clk2 = (new Clock(2)).clk(tick).clk(tick2, 1);


function speedTest(hz){
let stime = (new Date()).getTime();
function speedTest(hz, c){
c = (c) ? c : 1;
let stime = Date.now();
let ltime = stime;
let dt = 0; let dt = 0;
clk.hz = hz;
let _clk = (c === 1) ? clk : clk2;
_clk.hz = hz;
while (count < hz && dt < 1000){ while (count < hz && dt < 1000){
clk.tick();
dt = ((new Date()).getTime()) - stime;
let ctime = Date.now();
let _dt = ctime - ltime;
if (_dt > 0){
ltime = ctime;
_clk.tick(_dt);
}
dt = Date.now() - stime;
} }
return dt; return dt;
} }
}); });


it("4Khz for approx. 1 second", function(){ it("4Khz for approx. 1 second", function(){
count = 0;
let ts = 4000; let ts = 4000;
let d = ts * 0.01; let d = ts * 0.01;
let dt = speedTest(ts); let dt = speedTest(ts);
}); });


it("4Mhz for approx. 1 second", function(){ it("4Mhz for approx. 1 second", function(){
count = 0;
let ts = 4000000; let ts = 4000000;
let d = ts * 0.01; let d = ts * 0.01;
let dt = speedTest(ts); let dt = speedTest(ts);
expect(dt).to.be.gt(990); expect(dt).to.be.gt(990);
expect(dt).to.be.lt(1010); expect(dt).to.be.lt(1010);
}); });

it("4khz w/two layers for approx. 1 second", function(){
count = 0;
count2 = 0;
let ts = 4000;
let d = ts * 0.01;
let dt = speedTest(ts, 2);
expect(count).to.be.gt((ts*0.5) - dt);
expect(count).to.be.lt((ts*0.5) + dt);
expect(count2).to.be.gt((ts*0.5) - dt);
expect(count2).to.be.lt((ts*0.5) + dt);
expect(dt).to.be.gt(990);
expect(dt).to.be.lt(1010);
});
}); });

Loading…
Cancel
Save