cs142/project2/node_modules/date-now/test/index.js
2020-08-01 19:26:11 -03:00

29 lines
583 B
JavaScript

var test = require("tape")
var setTimeout = require("timers").setTimeout
var now = require("../index")
var seeded = require("../seed")
test("date", function (assert) {
var ts = now()
var ts2 = Date.now()
assert.equal(ts, ts2)
assert.end()
})
test("seeded", function (assert) {
var time = seeded(40)
var ts = time()
within(assert, time(), 40, 5)
setTimeout(function () {
within(assert, time(), 90, 10)
assert.end()
}, 50)
})
function within(assert, a, b, offset) {
assert.ok(a + offset > b)
assert.ok(a - offset < b)
}