test/min.test.js
zzmq.dev@gmail.com/mathkit / test / min.test.js
@ 9271926f
Download
Ladder Summary
- file Contains a comprehensive suite of unit tests for the min function, verifying correct operation across typical, edge‑case, and extreme inputs such as empty arguments, NaN, Infinity, negative values, and large numbers.
import { test } from "node:test";
import assert from "node:assert/strict";
import { min } from "../src/min.js";
test("min returns the smallest of multiple numbers", () => {
assert.strictEqual(min(3, 1, 4, 2), 1);
});
test("min works with negative numbers", () => {
assert.strictEqual(min(-7, -3, -10), -10);
});
test("min with mixed numbers", () => {
assert.strictEqual(min(-2, 0, 5, -1), -2);
});
test("min with single argument returns that argument", () => {
assert.strictEqual(min(99), 99);
});
test("min with no arguments returns Infinity", () => {
assert.strictEqual(min(), Infinity);
});
test("min propagates NaN if any argument is NaN", () => {
assert.ok(Number.isNaN(min(NaN, 1, 2)), "Result should be NaN when NaN is present");
assert.ok(Number.isNaN(min(5, NaN)), "Result should be NaN when NaN is present");
});
test("min correctly handles Infinity values", () => {
assert.strictEqual(min(Infinity, 1, 2), 1);
assert.strictEqual(min(-Infinity, -100, -200), -Infinity);
});
test("min works with very large numbers without overflow", () => {
const large1 = Number.MAX_SAFE_INTEGER;
const large2 = Number.MAX_SAFE_INTEGER - 1;
assert.strictEqual(min(large1, large2), large2);
});