forked from nikita/muzika-gromche
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import type { Assertion, JestAssertion } from "vitest";
|
|
import { describe, expect, test } from "vitest";
|
|
import type { Easing } from ".";
|
|
import { all, allNames, findEasingByName } from ".";
|
|
|
|
type NumberAssertion = {
|
|
[K in keyof Assertion<number>]: Assertion<number>[K] extends
|
|
(it: number) => void ? K : never;
|
|
}[keyof Assertion<number>];
|
|
|
|
function expectEasing(
|
|
easing: Easing,
|
|
middle: NumberAssertion,
|
|
): void {
|
|
expect(easing.eval(0)).toBe(0);
|
|
// despite the elaborate typing above, it still doesn't work without an as-cast
|
|
const ass = expect(easing.eval(0.5));
|
|
(ass[middle] as (it: number) => void)(0.5);
|
|
expect(easing.eval(1)).toBe(1);
|
|
}
|
|
|
|
describe("easing", () => {
|
|
test("baseline", () => {
|
|
expect(all).toBeDefined();
|
|
expect(allNames).toBeDefined();
|
|
expect(findEasingByName).toBeDefined();
|
|
expect(() => findEasingByName("")).not.toThrow();
|
|
const easing = findEasingByName("");
|
|
expect(easing).toBeDefined();
|
|
expect(easing.name).toBe("Linear");
|
|
expect(easing.eval).toBeDefined();
|
|
expect(() => easing.eval(0)).not.toThrow();
|
|
});
|
|
test("Linear", () => {
|
|
const easing = findEasingByName("Linear");
|
|
expectEasing(easing, "toBe");
|
|
});
|
|
test("InCubic", () => {
|
|
const easing = findEasingByName("InCubic");
|
|
expectEasing(easing, "toBeLessThan");
|
|
});
|
|
test("OutCubic", () => {
|
|
const easing = findEasingByName("OutCubic");
|
|
expectEasing(easing, "toBeGreaterThan");
|
|
});
|
|
test("InOutCubic", () => {
|
|
const easing = findEasingByName("InOutCubic");
|
|
expectEasing(easing, "toBe");
|
|
});
|
|
test("InExpo", () => {
|
|
const easing = findEasingByName("InExpo");
|
|
expectEasing(easing, "toBeLessThan");
|
|
});
|
|
test("OutExpo", () => {
|
|
const easing = findEasingByName("OutExpo");
|
|
expectEasing(easing, "toBeGreaterThan");
|
|
});
|
|
test("InOutExpo", () => {
|
|
const easing = findEasingByName("InOutExpo");
|
|
expectEasing(easing, "toBe");
|
|
});
|
|
test("find", () => {
|
|
expect(allNames).toContain("OutExpo");
|
|
expect(allNames).toContain("InOutCubic");
|
|
for (const name of allNames) {
|
|
const easing = findEasingByName(name);
|
|
expect(easing).toBeDefined();
|
|
expect(easing.name).toBe(name);
|
|
expect(all).toContain(easing);
|
|
}
|
|
});
|
|
});
|