test/gcd.test.js
zzmq.dev@gmail.com/mathkit / test / gcd.test.js
@ 9271926f
Download
Ladder Summary
- file Contains a test suite for the `gcd` function, covering basic cases, zero handling, negative numbers, and equal inputs, using Node’s built‑in test runner and strict assertions to verify correct behavior.
import { test } from "node:test";
import assert from "node:assert/strict";
import { gcd } from "../src/gcd.js";
test("gcd basic cases", () => {
assert.strictEqual(gcd(48, 18), 6);
assert.strictEqual(gcd(18, 48), 6);
});
test("gcd with zero", () => {
assert.strictEqual(gcd(0, 5), 5);
assert.strictEqual(gcd(5, 0), 5);
assert.strictEqual(gcd(0, 0), 0);
});
test("gcd with negative numbers", () => {
assert.strictEqual(gcd(-48, 18), 6);
assert.strictEqual(gcd(48, -18), 6);
assert.strictEqual(gcd(-48, -18), 6);
});
test("gcd with equal numbers", () => {
assert.strictEqual(gcd(13, 13), 13);
});