File size: 702 Bytes
5e0e982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { describe, expect, it } from "vitest";
import { project, rubberband, velocityFromSamples } from "./gestures";

describe("gestures", () => {
  it("projects velocity with Apple deceleration", () => {
    const distance = project(1000, 0.998);
    expect(distance).toBeCloseTo(499, 0);
  });

  it("rubberbands overshoot toward zero", () => {
    const pulled = rubberband(100, 300, 0.55);
    expect(pulled).toBeGreaterThan(0);
    expect(pulled).toBeLessThan(100);
  });

  it("computes velocity from pointer samples", () => {
    const v = velocityFromSamples(
      [
        { t: 0, x: 0, y: 0 },
        { t: 100, x: 0, y: 50 },
      ],
      "y",
    );
    expect(v).toBe(500);
  });
});