16
import { assert } from "chai"
17
import { Easing, EasingCurve, EasingStepJump } from "../../src/animation/Easing"
19
function assertEasing(easing: EasingCurve, ...expected: number[]) {
20
const last = expected.length - 1
21
for (let i = 0; i <= last; i++) {
22
assert.equal(Math.round(100 * easing(i / last)), expected[i])
26
suite("Easing", () => {
27
test("Linear", () => assertEasing(Easing.Linear, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100))
28
test("Linear.inverted", () => assertEasing(Easing.inverted(Easing.Linear), 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100))
29
test("Linear.reversed", () => assertEasing(Easing.reversed(Easing.Linear), 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0))
30
test("Linear.restarted", () => assertEasing(Easing.restarted(Easing.Linear), 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0))
31
test("Linear.repeated twice", () => assertEasing(Easing.repeated(Easing.Linear, 2), 0, 20, 40, 60, 80, 0, 20, 40, 60, 80, 100))
32
test("Linear.repeated 4 times", () => assertEasing(Easing.repeated(Easing.Linear, 4), 0, 40, 80, 20, 60, 0, 40, 80, 20, 60, 100))
33
test("Linear.joined with Linear.reversed", () => assertEasing(Easing.joined(Easing.Linear, Easing.reversed(Easing.Linear)), 0, 20, 40, 60, 80, 100, 80, 60, 40, 20, 0))
34
test("Linear.thereAndBackAgain (as above)", () => assertEasing(Easing.thereAndBackAgain(Easing.Linear), 0, 20, 40, 60, 80, 100, 80, 60, 40, 20, 0))
35
test("EaseInSine", () => assertEasing(Easing.EaseInSine, 0, 1, 5, 11, 19, 29, 41, 55, 69, 84, 100))
36
test("EaseInSine.inverted", () => assertEasing(Easing.inverted(Easing.EaseInSine), 0, 16, 31, 45, 59, 71, 81, 89, 95, 99, 100))
37
test("EaseInSine.reversed", () => assertEasing(Easing.reversed(Easing.EaseInSine), 100, 84, 69, 55, 41, 29, 19, 11, 5, 1, 0))
38
test("EaseOutSine", () => assertEasing(Easing.EaseOutSine, 0, 16, 31, 45, 59, 71, 81, 89, 95, 99, 100))
39
test("EaseOutSine.inverted", () => assertEasing(Easing.inverted(Easing.EaseOutSine), 0, 1, 5, 11, 19, 29, 41, 55, 69, 84, 100))
40
test("EaseOutSine.reversed", () => assertEasing(Easing.reversed(Easing.EaseOutSine), 100, 99, 95, 89, 81, 71, 59, 45, 31, 16, 0))
41
test("EaseInOutSine", () => assertEasing(Easing.EaseInOutSine, 0, 2, 10, 21, 35, 50, 65, 79, 90, 98, 100))
42
test("EaseInOutSine.inverted", () => assertEasing(Easing.inverted(Easing.EaseInOutSine), 0, 2, 10, 21, 35, 50, 65, 79, 90, 98, 100))
43
test("EaseInOutSine.reversed", () => assertEasing(Easing.reversed(Easing.EaseInOutSine), 100, 98, 90, 79, 65, 50, 35, 21, 10, 2, 0))
44
test("Ease", () => assertEasing(Easing.Ease, 0, 10, 30, 51, 68, 80, 89, 94, 98, 99, 100))
45
test("Ease.inverted", () => assertEasing(Easing.inverted(Easing.Ease), 0, 1, 2, 6, 11, 20, 32, 49, 70, 90, 100))
46
test("Ease.reversed", () => assertEasing(Easing.reversed(Easing.Ease), 100, 99, 98, 94, 89, 80, 68, 51, 30, 10, 0))
47
test("EaseIn", () => assertEasing(Easing.EaseIn, 0, 2, 6, 13, 21, 32, 43, 55, 69, 84, 100))
48
test("EaseIn.inverted", () => assertEasing(Easing.inverted(Easing.EaseIn), 0, 16, 31, 45, 57, 68, 79, 87, 94, 98, 100))
49
test("EaseIn.reversed", () => assertEasing(Easing.reversed(Easing.EaseIn), 100, 84, 69, 55, 43, 32, 21, 13, 6, 2, 0))
50
test("EaseOut", () => assertEasing(Easing.EaseOut, 0, 16, 31, 45, 57, 69, 79, 87, 94, 98, 100))
51
test("EaseOut.inverted", () => assertEasing(Easing.inverted(Easing.EaseOut), 0, 2, 6, 13, 21, 31, 43, 55, 69, 84, 100))
52
test("EaseOut.reversed", () => assertEasing(Easing.reversed(Easing.EaseOut), 100, 98, 94, 87, 79, 69, 57, 45, 31, 16, 0))
53
test("EaseInOut", () => assertEasing(Easing.EaseInOut, 0, 2, 8, 19, 33, 50, 67, 81, 92, 98, 100))
54
test("EaseInOut.inverted", () => assertEasing(Easing.inverted(Easing.EaseInOut), 0, 2, 8, 19, 33, 50, 67, 81, 92, 98, 100))
55
test("EaseInOut.reversed", () => assertEasing(Easing.reversed(Easing.EaseInOut), 100, 98, 92, 81, 67, 50, 33, 19, 8, 2, 0))
56
test("custom bezier with small overflow", () => assertEasing(Easing.cubicBezier(.3, -.3, .7, 1.3), 0, -4, 3, 15, 32, 50, 68, 85, 97, 104, 100))
57
test("custom bezier with large overflow", () => assertEasing(Easing.cubicBezier(.3, -.7, .7, 1.7), 0, -13, -9, 6, 26, 50, 74, 95, 109, 113, 100))
58
test("6 steps with EasingStepJump.None", () => assertEasing(Easing.steps(6, EasingStepJump.None), 0, 0, 20, 20, 40, 40, 60, 60, 80, 80, 100, 100))
59
test("11 steps with EasingStepJump.None", () => assertEasing(Easing.steps(11, EasingStepJump.None), 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100))
60
test("10 steps with EasingStepJump.Start", () => assertEasing(Easing.steps(10, EasingStepJump.Start), 10, 20, 30, 40, 50, 60, 70, 80, 90, 100))
61
test("10 steps with EasingStepJump.End", () => assertEasing(Easing.steps(10, EasingStepJump.End), 0, 10, 20, 30, 40, 50, 60, 70, 80, 90))
62
test("9 steps with EasingStepJump.Both", () => assertEasing(Easing.steps(9, EasingStepJump.Both), 10, 20, 30, 40, 50, 60, 70, 80, 90))