feat: define simulator data contracts
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
validateArrayDefinition,
|
||||
validateExperiment,
|
||||
validateScene,
|
||||
} from "/packages/contracts/validation.js";
|
||||
|
||||
async function loadJson(path) {
|
||||
const response = await fetch(path);
|
||||
assert(response.ok, `${path} load failed`);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
test("192채널 기준 배열이 계약을 통과한다", async () => {
|
||||
const arrayDefinition = await loadJson("/assets/array-geometries/rectangular-16x12.array.json");
|
||||
assertEqual(arrayDefinition.microphones.length, 192, "microphone count");
|
||||
assertEqual(validateArrayDefinition(arrayDefinition).length, 0, "array issues");
|
||||
});
|
||||
|
||||
test("단일 tone 장면과 실험이 관계 검증을 통과한다", async () => {
|
||||
const [arrayDefinition, scene, experiment] = await Promise.all([
|
||||
loadJson("/assets/array-geometries/rectangular-16x12.array.json"),
|
||||
loadJson("/assets/sample-scenes/single-tone.scene.json"),
|
||||
loadJson("/assets/sample-scenes/single-tone.experiment.json"),
|
||||
]);
|
||||
assertEqual(validateScene(scene).length, 0, "scene issues");
|
||||
assertEqual(validateExperiment(experiment, { arrayDefinition, scene }).length, 0, "experiment issues");
|
||||
});
|
||||
|
||||
test("중복 마이크 id를 거부한다", () => {
|
||||
const arrayDefinition = {
|
||||
schemaVersion: "1.0.0", kind: "micarrsim.array", id: "duplicate-test", name: "duplicate test", units: "m",
|
||||
coordinateSystem: { handedness: "right", xAxis: "right", yAxis: "up", zAxis: "toward-scene" },
|
||||
aperture: { width: 1, height: 1 },
|
||||
microphones: [
|
||||
{ id: "mic-1", position: [0, 0, 0] },
|
||||
{ id: "mic-1", position: [0.1, 0, 0] },
|
||||
],
|
||||
};
|
||||
assert(validateArrayDefinition(arrayDefinition).some(({ message }) => message.includes("중복")));
|
||||
});
|
||||
|
||||
test("Nyquist를 넘는 tone을 거부한다", () => {
|
||||
const scene = {
|
||||
schemaVersion: "1.0.0", kind: "micarrsim.scene", id: "nyquist-scene", name: "Nyquist test", units: "m",
|
||||
sampleRate: 8000, duration: 1, speedOfSound: 343, seed: 1,
|
||||
sources: [{
|
||||
id: "source", name: "source", position: [0, 0, 1], gainDb: 0, startTime: 0, duration: 1,
|
||||
signal: { type: "tone", frequency: 5000 },
|
||||
}],
|
||||
};
|
||||
assert(validateScene(scene).some(({ path }) => path.endsWith("frequency")));
|
||||
});
|
||||
|
||||
test("NaN 좌표를 거부한다", () => {
|
||||
const arrayDefinition = {
|
||||
schemaVersion: "1.0.0", kind: "micarrsim.array", id: "nan-test", name: "NaN test", units: "m",
|
||||
coordinateSystem: { handedness: "right", xAxis: "right", yAxis: "up", zAxis: "toward-scene" },
|
||||
aperture: { width: 1, height: 1 }, microphones: [{ id: "mic-1", position: [Number.NaN, 0, 0] }],
|
||||
};
|
||||
assert(validateArrayDefinition(arrayDefinition).some(({ path }) => path.endsWith("[0]")));
|
||||
});
|
||||
Reference in New Issue
Block a user