agenda/node_modules/randombytes/test.js
Edward Betts ea4980a5d7 Fix European trip return heuristic for weekend location tracking
Adjust European short trip heuristic from >3 days to >1 day to correctly
detect when user has returned home from European trips. This fixes the
April 29-30, 2023 case where the location incorrectly showed "Sankt Georg, Hamburg"
instead of "Bristol" when the user was free (no events scheduled) after
the foss-north trip ended on April 27.

The previous logic required more than 3 days to pass before assuming
return home from European countries, but for short European trips by
rail/ferry, users typically return within 1-2 days.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 06:38:37 +02:00

82 lines
1.8 KiB
JavaScript

var test = require('tape')
var randomBytes = require('./')
var MAX_BYTES = 65536
var MAX_UINT32 = 4294967295
test('sync', function (t) {
t.plan(9)
t.equals(randomBytes(0).length, 0, 'len: ' + 0)
t.equals(randomBytes(3).length, 3, 'len: ' + 3)
t.equals(randomBytes(30).length, 30, 'len: ' + 30)
t.equals(randomBytes(300).length, 300, 'len: ' + 300)
t.equals(randomBytes(17 + MAX_BYTES).length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
t.equals(randomBytes(MAX_BYTES * 100).length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
t.throws(function () {
randomBytes(MAX_UINT32 + 1)
})
t.throws(function () {
t.equals(randomBytes(-1))
})
t.throws(function () {
t.equals(randomBytes('hello'))
})
})
test('async', function (t) {
t.plan(9)
randomBytes(0, function (err, resp) {
if (err) throw err
t.equals(resp.length, 0, 'len: ' + 0)
})
randomBytes(3, function (err, resp) {
if (err) throw err
t.equals(resp.length, 3, 'len: ' + 3)
})
randomBytes(30, function (err, resp) {
if (err) throw err
t.equals(resp.length, 30, 'len: ' + 30)
})
randomBytes(300, function (err, resp) {
if (err) throw err
t.equals(resp.length, 300, 'len: ' + 300)
})
randomBytes(17 + MAX_BYTES, function (err, resp) {
if (err) throw err
t.equals(resp.length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
})
randomBytes(MAX_BYTES * 100, function (err, resp) {
if (err) throw err
t.equals(resp.length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
})
t.throws(function () {
randomBytes(MAX_UINT32 + 1, function () {
t.ok(false, 'should not get here')
})
})
t.throws(function () {
randomBytes(-1, function () {
t.ok(false, 'should not get here')
})
})
t.throws(function () {
randomBytes('hello', function () {
t.ok(false, 'should not get here')
})
})
})