55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { WavCodec } from "@suaveplan/audio-codecs";
|
|
import {
|
|
afterEach,
|
|
beforeEach,
|
|
describe,
|
|
expect,
|
|
it,
|
|
} from "@suaveplan/testing/runner";
|
|
import fc from "fast-check";
|
|
import { FileSinkAdapter, FileSourceAdapter } from "../src/index.js";
|
|
|
|
describe("property: load+save round-trip preserves sample count", () => {
|
|
let dir: string;
|
|
|
|
beforeEach(async () => {
|
|
dir = await mkdtemp(join(tmpdir(), "aes-prop-"));
|
|
});
|
|
afterEach(async () => {
|
|
await rm(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
it("load then save preserves sample count across a real tmpdir round-trip", {
|
|
timeout: 30_000,
|
|
}, async () => {
|
|
await fc.assert(
|
|
fc.asyncProperty(
|
|
fc.integer({ min: 16, max: 256 }),
|
|
async (samples) => {
|
|
const inPath = join(dir, `i-${samples}.wav`);
|
|
const outPath = join(dir, `o-${samples}.wav`);
|
|
const wav = await WavCodec.encode(
|
|
[new Float32Array(samples)],
|
|
{
|
|
sampleRate: 44_100,
|
|
bitDepth: 16,
|
|
format: "pcm",
|
|
}
|
|
);
|
|
await writeFile(inPath, wav);
|
|
const source = new FileSourceAdapter();
|
|
const sink = new FileSinkAdapter();
|
|
const doc = await source.load(inPath);
|
|
await sink.save(doc, outPath, "wav");
|
|
const back = await source.load(outPath);
|
|
expect(back.sourceLength).toBe(samples);
|
|
}
|
|
),
|
|
{ numRuns: 5 }
|
|
);
|
|
});
|
|
});
|