From a8476dedd4742a79227542e17887191f7be4ab43 Mon Sep 17 00:00:00 2001 From: marcin2121 <13873718+marcin2121@users.noreply.github.com> Date: Tue, 31 Mar 2026 19:36:12 +0000 Subject: [PATCH] test(engine): add tests for calculateDecay zero bound Adds comprehensive unit tests for the calculateDecay function in lib/urwis/engine.ts. The tests focus on validating the zero bounding logic to ensure that decayed values never drop below zero, handling edge cases such as extremely large time elapsed, zero initial values, and negative initial values. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- lib/urwis/engine.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/urwis/engine.test.ts diff --git a/lib/urwis/engine.test.ts b/lib/urwis/engine.test.ts new file mode 100644 index 0000000..c5c7098 --- /dev/null +++ b/lib/urwis/engine.test.ts @@ -0,0 +1,21 @@ +import { test, describe } from 'node:test'; +import * as assert from 'node:assert'; +import { calculateDecay } from './engine'; + +describe('calculateDecay', () => { + describe('Zero Bound', () => { + test('bounds the result to 0 when a large amount of time has passed', () => { + // 1000000 seconds is large enough to decay any small value to 0, regardless of the exact rate + assert.strictEqual(calculateDecay(10, 1000000), 0); + }); + + test('returns 0 when initial value is 0', () => { + assert.strictEqual(calculateDecay(0, 10), 0); + }); + + test('returns 0 when initial value is negative', () => { + // Bounding should ensure negative values are clamped to 0 + assert.strictEqual(calculateDecay(-10, 10), 0); + }); + }); +});