2016-04-18 17:20:30 -04:00
|
|
|
var test = require('tap').test;
|
|
|
|
var Timer = require('../../src/util/timer');
|
|
|
|
|
|
|
|
test('spec', function (t) {
|
|
|
|
var timer = new Timer();
|
|
|
|
|
|
|
|
t.type(Timer, 'function');
|
|
|
|
t.type(timer, 'object');
|
|
|
|
|
|
|
|
t.type(timer.startTime, 'number');
|
|
|
|
t.type(timer.time, 'function');
|
|
|
|
t.type(timer.start, 'function');
|
2016-04-26 17:03:22 -04:00
|
|
|
t.type(timer.timeElapsed, 'function');
|
2016-04-18 17:20:30 -04:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('time', function (t) {
|
|
|
|
var timer = new Timer();
|
|
|
|
var time = timer.time();
|
|
|
|
|
|
|
|
t.ok(Date.now() >= time);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2016-04-26 17:03:22 -04:00
|
|
|
test('start / timeElapsed', function (t) {
|
2016-04-18 17:20:30 -04:00
|
|
|
var timer = new Timer();
|
|
|
|
var delay = 100;
|
|
|
|
var threshold = 1000 / 60; // 60 hz
|
|
|
|
|
|
|
|
// Start timer
|
|
|
|
timer.start();
|
|
|
|
|
2016-04-26 17:03:22 -04:00
|
|
|
// Wait and measure timer
|
2016-04-18 17:20:30 -04:00
|
|
|
setTimeout(function () {
|
2016-04-26 17:03:22 -04:00
|
|
|
var timeElapsed = timer.timeElapsed();
|
|
|
|
t.ok(timeElapsed >= 0);
|
|
|
|
t.ok(timeElapsed >= (delay - threshold) &&
|
|
|
|
timeElapsed <= (delay + threshold));
|
2016-04-18 17:20:30 -04:00
|
|
|
t.end();
|
|
|
|
}, delay);
|
|
|
|
});
|