The first commit, the core and all files is adding to repo
This commit is contained in:
75
tests/protocol.test.ts
Normal file
75
tests/protocol.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { boundsSchema, datasetSchema, scoreGuess } from "../shared/protocol";
|
||||
const bounds = { minX: -512, minZ: -256, maxX: 512, maxZ: 256 };
|
||||
test("horizontal scoring ignores elevation and handles negative coordinates", () => {
|
||||
assert.equal(
|
||||
scoreGuess({ x: -13, z: -25 }, { x: -13, z: -25 }, bounds).score,
|
||||
5000,
|
||||
);
|
||||
assert.equal(scoreGuess({ x: 0, z: 0 }, { x: 1, z: 0 }, bounds).score, 5000);
|
||||
assert.equal(
|
||||
scoreGuess({ x: -50, z: 0 }, { x: 50, z: 0 }, bounds).distance,
|
||||
100,
|
||||
);
|
||||
assert.ok(
|
||||
scoreGuess({ x: 0, z: 0 }, { x: 100, z: 100 }, bounds).score < 5000,
|
||||
);
|
||||
});
|
||||
test("invalid, zero, and oversized bounds cannot enter rendering", () => {
|
||||
assert.equal(
|
||||
boundsSchema.safeParse({ ...bounds, maxX: -512 }).success,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
boundsSchema.safeParse({ ...bounds, maxX: 3000 }).success,
|
||||
false,
|
||||
);
|
||||
assert.equal(boundsSchema.safeParse(bounds).success, true);
|
||||
});
|
||||
test("dataset requires five unique in-bounds viewpoints and safe paths", () => {
|
||||
const base = {
|
||||
format: "minegeo-dataset/v1",
|
||||
minecraftVersion: "1.21.11",
|
||||
dimension: "minecraft:overworld",
|
||||
source: "plugin",
|
||||
name: "Test map",
|
||||
serverName: "Test server",
|
||||
north: "-z",
|
||||
bounds,
|
||||
viewpoints: Array.from({ length: 5 }, (_, i) => ({
|
||||
id: `p${i}`,
|
||||
x: i,
|
||||
y: 70,
|
||||
z: i,
|
||||
})),
|
||||
assets: [{ path: "terrain.json.gz", sha256: "a".repeat(64), bytes: 100 }],
|
||||
};
|
||||
assert.equal(datasetSchema.safeParse(base).success, true);
|
||||
assert.equal(
|
||||
datasetSchema.safeParse({ ...base, viewpoints: base.viewpoints.slice(1) })
|
||||
.success,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
datasetSchema.safeParse({
|
||||
...base,
|
||||
assets: [{ ...base.assets[0], path: "../secrets" }],
|
||||
}).success,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
datasetSchema.safeParse({
|
||||
...base,
|
||||
viewpoints: base.viewpoints.map((p) => ({ ...p, id: "same" })),
|
||||
}).success,
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
datasetSchema.safeParse({
|
||||
...base,
|
||||
viewpoints: base.viewpoints.map((p) => ({ ...p, x: 9999 })),
|
||||
}).success,
|
||||
false,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user