Skip to content

Commit

Permalink
feat: add Vector4 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 22, 2020
1 parent d492098 commit 1ed06e0
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "tgt & tsc",
"dev": "npm run watch & npm start",
"lint": "eslint ./src/",
"start": "es-dev-server --node-resolve --watch --http2",
"start": "es-dev-server --node-resolve --watch",
"docs": "typedoc",
"watch": "tsc --watch & tgt --watch",
"postinstall": "cp --remove-destination ./hooks/prepare-commit-msg ./.git/hooks/prepare-commit-msg && chmod +x ./.git/hooks/prepare-commit-msg"
Expand Down
1 change: 1 addition & 0 deletions src/examples/units/glsl/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"slug": "glsl_unit_tests",
"thumbnail": "manual",
"en": {
"name": "GLSL Unit Test Runner",
"description": "Runs all the glsl unit tests.",
Expand Down
52 changes: 31 additions & 21 deletions src/lib/math/Euler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,40 @@ function delta(a: Euler, b: Euler): number {
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y) + Math.abs(a.z - b.z);
}

test("Instancing", () => {
const a = new Euler();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
expect(a.z).toBe(0);
expect(a.order).toBe(EulerOrder.Default);
describe("Euler", () => {
test("constructor defaults", () => {
const a = new Euler();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
expect(a.z).toBe(0);
expect(a.order).toBe(EulerOrder.Default);
});

const b = new Euler(1, 2, 3, EulerOrder.ZXY);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
expect(b.z).toBe(3);
expect(b.order).toBe(EulerOrder.ZXY);
test("constructor values", () => {
const b = new Euler(1, 2, 3, EulerOrder.ZXY);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
expect(b.z).toBe(3);
expect(b.order).toBe(EulerOrder.ZXY);
});

const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
expect(c.order).toBe(EulerOrder.ZXY);
test("clone", () => {
const b = new Euler(1, 2, 3, EulerOrder.ZXY);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
expect(c.order).toBe(EulerOrder.ZXY);
});

const d = new Euler().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
expect(d.order).toBe(EulerOrder.ZXY);
test("copy", () => {
const b = new Euler(1, 2, 3, EulerOrder.ZXY);
const d = new Euler().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
expect(d.order).toBe(EulerOrder.ZXY);
});
});

describe("Euler-Quaternion", () => {
Expand Down
60 changes: 31 additions & 29 deletions src/lib/math/Quaternion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,40 @@ const qXZW = new Quaternion(0.5, 0, 1, 0.25).normalize();
const testValues = [qX, qY, qZ, qW, qXY, qYZ, qXZ, qXYZ, qXYW, qYZW, qXZW];
const testOrders = [EulerOrder.XYZ, EulerOrder.YXZ, EulerOrder.ZXY, EulerOrder.ZYX, EulerOrder.YZX, EulerOrder.XZY];

test("Constructor", () => {
const a = new Quaternion();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
expect(a.z).toBe(0);
expect(a.w).toBe(1);
});
describe("Quaternionr", () => {
test("constructor defaults", () => {
const a = new Quaternion();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
expect(a.z).toBe(0);
expect(a.w).toBe(1);
});

test("Constructor Values", () => {
const b = new Quaternion(1, 2, 3, 4);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
expect(b.z).toBe(3);
expect(b.w).toBe(4);
});
test("constructor Values", () => {
const b = new Quaternion(1, 2, 3, 4);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
expect(b.z).toBe(3);
expect(b.w).toBe(4);
});

test("Clone", () => {
const b = new Quaternion(1, 2, 3, 4);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
expect(c.w).toBe(4);
});
test("clone", () => {
const b = new Quaternion(1, 2, 3, 4);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
expect(c.w).toBe(4);
});

test("Copy", () => {
const b = new Quaternion(1, 2, 3, 4);
const d = new Quaternion().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
expect(d.w).toBe(4);
test("copy", () => {
const b = new Quaternion(1, 2, 3, 4);
const d = new Quaternion().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
expect(d.w).toBe(4);
});
});

describe("Quaternion-Euler ", () => {
Expand Down
36 changes: 23 additions & 13 deletions src/lib/math/Vector2.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { Vector2 } from "./Vector2";

test("Instancing", () => {
const a = new Vector2();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
describe("Vector2", () => {
test("constructor defaults", () => {
const a = new Vector2();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
});

const b = new Vector2(1, 2);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
test("constructor values", () => {
const b = new Vector2(1, 2);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
});

const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
test("clone", () => {
const b = new Vector2(1, 2);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
});

const d = new Vector2().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
test("copy", () => {
const b = new Vector2(1, 2);
const d = new Vector2().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
});
});
46 changes: 27 additions & 19 deletions src/lib/math/Vector3.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { Vector3 } from "./Vector3";

test("Instancing", () => {
const a = new Vector3();
expect(a.r).toBe(0);
expect(a.g).toBe(0);
expect(a.b).toBe(0);
describe("Vector3", () => {
test("constructor defaults", () => {
const a = new Vector3();
expect(a.r).toBe(0);
expect(a.g).toBe(0);
expect(a.b).toBe(0);
});

const b = new Vector3(1, 2, 3);
expect(b.r).toBe(1);
expect(b.g).toBe(2);
expect(b.b).toBe(3);

const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);

const d = new Vector3().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
test("constructor values", () => {
const b = new Vector3(1, 2, 3);
expect(b.r).toBe(1);
expect(b.g).toBe(2);
expect(b.b).toBe(3);
});
test("clone", () => {
const b = new Vector3(1, 2, 3);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
});
test("copy", () => {
const b = new Vector3(1, 2, 3);
const d = new Vector3().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
});
});
35 changes: 35 additions & 0 deletions src/lib/math/Vector4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Vector4 } from "./Vector4";

describe("Vector4", () => {
test("constructor defaults", () => {
const a = new Vector4();
expect(a.x).toBe(0);
expect(a.y).toBe(0);
expect(a.z).toBe(0);
expect(a.w).toBe(0);
});

test("constructor values", () => {
const b = new Vector4(1, 2, 3, 4);
expect(b.x).toBe(1);
expect(b.y).toBe(2);
expect(b.z).toBe(3);
expect(b.w).toBe(4);
});
test("clone", () => {
const b = new Vector4(1, 2, 3, 4);
const c = b.clone();
expect(c.x).toBe(1);
expect(c.y).toBe(2);
expect(c.z).toBe(3);
expect(c.w).toBe(4);
});
test("copy", () => {
const b = new Vector4(1, 2, 3, 4);
const d = new Vector4().copy(b);
expect(d.x).toBe(1);
expect(d.y).toBe(2);
expect(d.z).toBe(3);
expect(d.w).toBe(4);
});
});

0 comments on commit 1ed06e0

Please sign in to comment.