Przeglądaj źródła

Clock tests updated for new features.

master
Bryan Miller 5 lat temu
rodzic
commit
1309eca595
1 zmienionych plików z 32 dodań i 5 usunięć
  1. +32
    -5
      test/unit.src.clock.spec.js

+ 32
- 5
test/unit.src.clock.spec.js Wyświetl plik

@@ -4,16 +4,27 @@ const Clock = require('../src/clock.js');

describe("Clock Tests", function(){
var count = 0;
var count2 = 0;
var tick = ()=>{count += 1;};
var tick2 = () =>{count2 += 1;};
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;
clk.hz = hz;
let _clk = (c === 1) ? clk : clk2;
_clk.hz = hz;
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;
}
@@ -25,6 +36,7 @@ describe("Clock Tests", function(){
});

it("4Khz for approx. 1 second", function(){
count = 0;
let ts = 4000;
let d = ts * 0.01;
let dt = speedTest(ts);
@@ -35,6 +47,7 @@ describe("Clock Tests", function(){
});

it("4Mhz for approx. 1 second", function(){
count = 0;
let ts = 4000000;
let d = ts * 0.01;
let dt = speedTest(ts);
@@ -43,4 +56,18 @@ describe("Clock Tests", function(){
expect(dt).to.be.gt(990);
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);
});
});

Ładowanie…
Anuluj
Zapisz