18 lines
659 B
TypeScript
18 lines
659 B
TypeScript
import { assertEquals } from "@std/assert";
|
|
import { peaksOf } from "../waveform.ts";
|
|
|
|
Deno.test("peaksOf: each slice's loudest sample, scaled to the loudest", () => {
|
|
assertEquals(peaksOf([0.1, -0.5, 0.2, 0.25, -0.1, 0.05], 3), [1, 0.5, 0.2]);
|
|
});
|
|
|
|
Deno.test("peaksOf: every sample counts, however they divide", () => {
|
|
assertEquals(peaksOf([0, 0, 0, 0, 0, 0, 0.8], 3), [0, 0, 1]);
|
|
// Fewer samples than peaks: neighbours share one.
|
|
assertEquals(peaksOf([0.5, 1], 4), [0.5, 0.5, 1, 1]);
|
|
});
|
|
|
|
Deno.test("peaksOf: silence is flat, not divided by zero", () => {
|
|
assertEquals(peaksOf([0, 0, 0], 2), [0, 0]);
|
|
assertEquals(peaksOf([], 2), [0, 0]);
|
|
});
|