Slash-The-Hordes/tests/utils/mathUtils.test.ts
2022-12-15 11:14:35 +01:00

17 lines
642 B
TypeScript

import { getDegreeAngleFromDirection } from "../../assets/Scripts/Services/Utils/MathUtils";
const testCases: { x: number; y: number; expectedAngle: number }[] = [
{ x: 0.5, y: 0.5, expectedAngle: 45 },
{ x: 0, y: 1, expectedAngle: 90 },
{ x: -0.5, y: -0.5, expectedAngle: 225 }
];
for (const testCase of testCases) {
test(`returns correct degree angle for direction [X: ${testCase.x} , Y: ${testCase.y}] (${testCase.expectedAngle} degrees)`, () => {
let angle = getDegreeAngleFromDirection(testCase.x, testCase.y);
if (angle < 0) angle += 360;
expect(angle).toBe(testCase.expectedAngle);
});
}