Disposable programming case study
Goal: reject reversed bounds in a pure clamp(value, min, max) utility.
Acceptance criteria:
- values inside the interval are unchanged;
- values below or above are clamped;
- exact boundaries are preserved;
- min greater than max throws RangeError.
Files: before.mjs, after.mjs, change.patch, test.mjs, and test-results.txt.
Reproduce with Node 26:
node test.mjsVerified on 2026-10-27 with Node v26.8.1: PASS 6 clamp assertions.
Limits: this is a synthetic disposable utility. Packaging, browser behavior, accessibility, dependencies, integration, and deployment are NOT_TESTED.
Included source files
- README.md MARKDOWN
- before.mjs JAVASCRIPT
- after.mjs JAVASCRIPT
- change.patch PATCH
- test.mjs JAVASCRIPT
- test-results.txt TEXT
before.mjs
Download this fileexport function clamp(value, min, max) {
return Math.min(max, Math.max(min, value));
}after.mjs
Download this fileexport function clamp(value, min, max) {
if (min > max) throw new RangeError('min must not exceed max');
return Math.min(max, Math.max(min, value));
}change.patch
Download this file--- before.mjs
+++ after.mjs
@@
export function clamp(value, min, max) {
+ if (min > max) throw new RangeError('min must not exceed max');
return Math.min(max, Math.max(min, value));
}test.mjs
Download this fileimport assert from 'node:assert/strict';
import { clamp } from './after.mjs';
assert.equal(clamp(5, 0, 10), 5);
assert.equal(clamp(-2, 0, 10), 0);
assert.equal(clamp(12, 0, 10), 10);
assert.equal(clamp(0, 0, 10), 0);
assert.equal(clamp(10, 0, 10), 10);
assert.throws(() => clamp(5, 10, 0), RangeError);
console.log('PASS 6 clamp assertions');test-results.txt
Download this fileDate: 2026-10-27
Runtime: Node v26.8.1
Command: node test.mjs
Result: PASS 6 clamp assertions