Enable flashlight at sunset and switch primary night action

This commit is contained in:
2026-10-31 23:27:14 +09:00
parent eb49ea4b84
commit ff86bdb5b5
5 changed files with 49 additions and 11 deletions
+14
View File
@@ -0,0 +1,14 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { flashlightAfterSunUpdate } from '../src/controls/flashlight.ts';
test('sunset enables the flashlight once, preserves manual off, and resets at dawn', () => {
assert.equal(flashlightAfterSunUpdate(false, undefined, 20), false);
assert.equal(flashlightAfterSunUpdate(false, 1, -0.1), false, 'wait until the solar disc has set');
assert.equal(flashlightAfterSunUpdate(false, -0.1, -1), true);
assert.equal(flashlightAfterSunUpdate(false, -1, -2), false, 'manual off survives time updates');
assert.equal(flashlightAfterSunUpdate(true, -2, -3), true);
assert.equal(flashlightAfterSunUpdate(true, -3, 1), false);
assert.equal(flashlightAfterSunUpdate(false, 1, -1), true, 'next night enables again');
assert.equal(flashlightAfterSunUpdate(false, undefined, -10), true, 'nighttime arrival enables the torch');
});