import { describe, expect, it } from "vitest";

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).toEqual(0);
    expect(v0.y).toEqual(0);
  });

  it("should create a vector", () => {
    expect(v.x).toEqual(1);
    expect(v.y).toEqual(2);
  });

  it("should add vectors", () => {
    const v2 = v.plus(new Vector2D(3, 4));
    expect(v2.x).toEqual(4);
    expect(v2.y).toEqual(6);
  });

  it("should subtract vectors", () => {
    const v2 = v.minus(new Vector2D(3, 4));
    expect(v2.x).toEqual(-2);
    expect(v2.y).toEqual(-2);
  });

  it("should scale vectors", () => {
    const v2 = v.scale(3);
    expect(v2.x).toEqual(3);
    expect(v2.y).toEqual(6);
  });

  it("should compare vectors", () => {
    expect(v.equals(v.scale(1))).toBe(true);
    expect(v.equals(v.scale(2))).toBe(false);
  });
});
