41 lines
968 B
TypeScript
41 lines
968 B
TypeScript
import { expect } from "chai";
|
|
|
|
import { Vector2D } from "@/lib/rects/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;
|
|
});
|
|
});
|