Something went wrong. Try again.
Your thinking partner.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { expect, test } from "bun:test";import { ParticleMotion, particlePaths, MORPH_MS } from "./particleMotion";
test("idle is still; real activity morphs in and a stop returns to the ring", () => { const motion = new ParticleMotion("ring"); expect(motion.active).toBe(false); expect(motion.frame(10000).glyph).toBe("ring"); motion.setTarget("orb"); expect(motion.frame(MORPH_MS / 2).glyph).toBeNull(); motion.frame(MORPH_MS / 2); expect(motion.active).toBe(true); const first = motion.frame(10).dots; expect(motion.frame(4100).dots).not.toEqual(first); motion.setTarget("ring"); expect(motion.frame(MORPH_MS).glyph).toBe("ring"); expect(motion.active).toBe(false);});
test("rapid plus/minus reversals preserve finite, visible particle geometry", () => { const motion = new ParticleMotion("plus"); for (let i = 0; i < 12; i++) { motion.setTarget(i % 2 ? "plus" : "minus"); const frame = motion.frame(45); expect( frame.dots.every( (d) => Number.isFinite(d.x + d.y + d.r + d.alpha) && d.r > 0, ), ).toBe(true); expect(particlePaths(frame.dots).join("")).not.toContain("NaN"); } motion.setTarget("minus"); const result = motion.frame(MORPH_MS); expect(result.glyph).toBe("minus"); expect(result.dots.every((d) => d.y === 22)).toBe(true);});
test("reduced motion snaps between symbols and keeps the orb still", () => { const motion = new ParticleMotion("ring"); motion.setTarget("orb", true); const frame = motion.frame(0, true); expect(motion.frame(10000, true)).toEqual(frame); motion.setTarget("ring", true); expect(motion.frame(0, true).glyph).toBe("ring");});
test("interrupting the ring transition at any phase returns cleanly", () => { for (const delay of [0, 1, 60, 224, 225, 4200]) { const motion = new ParticleMotion("ring"); motion.setTarget("orb"); motion.frame(delay); motion.setTarget("ring"); expect(motion.frame(MORPH_MS).glyph).toBe("ring"); }});