mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-27 09:53:01 +00:00
41 lines
962 B
TypeScript
41 lines
962 B
TypeScript
import { expect } from "chai";
|
|
|
|
import { Vector2D } from "@/lib/vector2d";
|
|
|
|
describe("Vector2D Tests", () => {
|
|
const v = new Vector2D(1, 2);
|
|
|
|
it("should create a default vector", () => {
|
|
const v0 = new Vector2D();
|
|
expect(v0.x).to.equal(0);
|
|
expect(v0.y).to.equal(0);
|
|
});
|
|
|
|
it("should create a vector", () => {
|
|
expect(v.x).to.equal(1);
|
|
expect(v.y).to.equal(2);
|
|
});
|
|
|
|
it("should add vectors", () => {
|
|
const v2 = v.plus(new Vector2D(3, 4));
|
|
expect(v2.x).to.equal(4);
|
|
expect(v2.y).to.equal(6);
|
|
});
|
|
|
|
it("should subtract vectors", () => {
|
|
const v2 = v.minus(new Vector2D(3, 4));
|
|
expect(v2.x).to.equal(-2);
|
|
expect(v2.y).to.equal(-2);
|
|
});
|
|
|
|
it("should scale vectors", () => {
|
|
const v2 = v.scale(3);
|
|
expect(v2.x).to.equal(3);
|
|
expect(v2.y).to.equal(6);
|
|
});
|
|
|
|
it("should compare vectors", () => {
|
|
expect(v.equals(v.scale(1))).to.be.true;
|
|
expect(v.equals(v.scale(2))).to.be.false;
|
|
});
|
|
});
|