26 lines
685 B
TypeScript
26 lines
685 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { add, scale, sub, vec } from "./vector.ts";
|
|
|
|
test("vec builds a vector", () => {
|
|
expect(vec(2, 3)).toEqual({ x: 2, y: 3 });
|
|
});
|
|
|
|
test("add is component-wise", () => {
|
|
expect(add(vec(1, 2), vec(3, 4))).toEqual({ x: 4, y: 6 });
|
|
});
|
|
|
|
test("sub is component-wise", () => {
|
|
expect(sub(vec(5, 5), vec(1, 2))).toEqual({ x: 4, y: 3 });
|
|
});
|
|
|
|
test("scale multiplies both components", () => {
|
|
expect(scale(vec(2, 3), 2)).toEqual({ x: 4, y: 6 });
|
|
expect(scale(vec(2, 3), 0)).toEqual({ x: 0, y: 0 });
|
|
});
|
|
|
|
test("inputs are not mutated (pure functions)", () => {
|
|
const a = vec(1, 2);
|
|
add(a, vec(3, 4));
|
|
expect(a).toEqual({ x: 1, y: 2 });
|
|
});
|