Skip to content

Commit 6ca85c1

Browse files
committed
test: entities/score - ease 베지어 이징 수치 정확도 테스트 추가
1 parent 828d764 commit 6ca85c1

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, it, expect } from "vitest";
2+
import { ease } from "../ease";
3+
4+
/**
5+
* 베지어 제어점: p1=(0.67, 0.005), p2=(0.27, 1.0)
6+
*
7+
* 계수:
8+
* cx = 2.01, bx = -3.21, ax = 2.2
9+
* cy = 0.015, by = 2.97, ay = -1.985
10+
*
11+
* 기준점 (매개변수 t에서의 정확한 (X, Y) 값):
12+
* t=0.25 → X=0.33625, Y≈0.158359
13+
* t=0.5 → X=0.4775, Y≈0.501875
14+
* t=0.75 → X=0.63, Y≈0.844453
15+
*/
16+
17+
describe("ease - 경계 조건", () => {
18+
it("ease(0)은 0을 반환한다", () => {
19+
expect(ease(0)).toBe(0);
20+
});
21+
22+
it("ease(1)은 1을 반환한다", () => {
23+
expect(ease(1)).toBe(1);
24+
});
25+
26+
it("음수 입력은 0을 반환한다", () => {
27+
expect(ease(-0.1)).toBe(0);
28+
expect(ease(-1)).toBe(0);
29+
});
30+
31+
it("1 초과 입력은 1을 반환한다", () => {
32+
expect(ease(1.1)).toBe(1);
33+
expect(ease(2)).toBe(1);
34+
});
35+
});
36+
37+
describe("ease - 수치 정확도", () => {
38+
it("t=0.5에서의 베지어 값을 정확히 계산한다 (x=0.4775 → y≈0.501875)", () => {
39+
// X(0.5) = 0.4775, Y(0.5) = 0.501875
40+
expect(ease(0.4775)).toBeCloseTo(0.501875, 5);
41+
});
42+
43+
it("t=0.25에서의 베지어 값을 정확히 계산한다 (x=0.33625 → y≈0.158359)", () => {
44+
// X(0.25) = 0.33625, Y(0.25) = 0.158359375
45+
expect(ease(0.33625)).toBeCloseTo(0.158359, 5);
46+
});
47+
48+
it("t=0.75에서의 베지어 값을 정확히 계산한다 (x=0.63 → y≈0.844453)", () => {
49+
// X(0.75) = 0.63, Y(0.75) = 0.844453125
50+
expect(ease(0.63)).toBeCloseTo(0.844453, 5);
51+
});
52+
});
53+
54+
describe("ease - 단조증가 및 범위", () => {
55+
it("출력이 항상 [0, 1] 범위에 있다", () => {
56+
const samples = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
57+
for (const x of samples) {
58+
const y = ease(x);
59+
expect(y).toBeGreaterThanOrEqual(0);
60+
expect(y).toBeLessThanOrEqual(1);
61+
}
62+
});
63+
64+
it("단조증가 성질을 만족한다", () => {
65+
const samples = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
66+
const outputs = samples.map(ease);
67+
for (let i = 0; i < outputs.length - 1; i++) {
68+
expect(outputs[i]).toBeLessThan(outputs[i + 1]);
69+
}
70+
});
71+
});

0 commit comments

Comments
 (0)