Add tests for computeSoundEmitterDistanceGain function

This commit is contained in:
2026-04-02 20:04:46 +02:00
parent 2b87e384b8
commit fa345b6536

View File

@@ -0,0 +1,14 @@
import { describe, expect, it } from "vitest";
import { computeSoundEmitterDistanceGain } from "../../src/runtime-three/runtime-audio-system";
describe("computeSoundEmitterDistanceGain", () => {
it("keeps full volume near the emitter and eases smoothly to silence at max distance", () => {
expect(computeSoundEmitterDistanceGain(4, 6, 24)).toBe(1);
expect(computeSoundEmitterDistanceGain(6, 6, 24)).toBe(1);
expect(computeSoundEmitterDistanceGain(12, 6, 24)).toBeGreaterThan(2 / 3);
expect(computeSoundEmitterDistanceGain(18, 6, 24)).toBeLessThan(1 / 3);
expect(computeSoundEmitterDistanceGain(24, 6, 24)).toBe(0);
expect(computeSoundEmitterDistanceGain(30, 6, 24)).toBe(0);
});
});