feat(coords): Chunk-Namen als Planquadrat A1 bis L12
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44108f94f4
commit
2f63779363
5 files changed
+120
-2
No files matched your search
+40
-1
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { CHUNK_SIZE, chunkForWorld, threeToWorld, tileForWorld, worldToThree } from "../src/world/coords.js";
|
||||
import fs from "node:fs";
|
||||
import { CHUNK_SIZE, chunkForWorld, chunkName, parseChunkName, threeToWorld, tileForWorld, worldToThree } from "../src/world/coords.js";
|
||||
|
||||
const NAMES = JSON.parse(fs.readFileSync(new URL("./fixtures/chunk-names.json", import.meta.url), "utf8"));
|
||||
|
||||
describe("coords", () => {
|
||||
it("dreht Y zur three-z-Achse", () => {
|
||||
@@ -22,3 +25,39 @@ describe("coords", () => {
|
||||
expect(chunkForWorld(1999, -499)).toEqual({ i: 11, j: 11 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Chunk-Namen", () => {
|
||||
it("benennt Ecken und Beispiel wie in der Spec, in beide Richtungen", () => {
|
||||
for (const [name, i, j] of NAMES.pairs) {
|
||||
expect(chunkName(i, j)).toBe(name);
|
||||
expect(parseChunkName(name)).toEqual({ i, j });
|
||||
}
|
||||
});
|
||||
|
||||
it("akzeptiert Kleinschreibung", () => {
|
||||
for (const [name, i, j] of NAMES.lowercase) expect(parseChunkName(name)).toEqual({ i, j });
|
||||
});
|
||||
|
||||
it("weist alles außerhalb von A1 bis L12 ab", () => {
|
||||
for (const name of NAMES.invalid) expect(parseChunkName(name)).toBeNull();
|
||||
});
|
||||
|
||||
it("liefert null für Indizes außerhalb des Ausschnitts", () => {
|
||||
expect(chunkName(12, 0)).toBeNull();
|
||||
expect(chunkName(0, 12)).toBeNull();
|
||||
expect(chunkName(-1, 3)).toBeNull();
|
||||
expect(chunkName(1.5, 3)).toBeNull();
|
||||
});
|
||||
|
||||
it("kommt für alle 144 Chunks hin und zurück", () => {
|
||||
for (let i = 0; i < 12; i++) {
|
||||
for (let j = 0; j < 12; j++) expect(parseChunkName(chunkName(i, j))).toEqual({ i, j });
|
||||
}
|
||||
});
|
||||
|
||||
it("verbindet den Namen mit der Lage: der Downtown-Kern liegt in B9", () => {
|
||||
const { i, j } = chunkForWorld(-511, 254);
|
||||
expect({ i, j }).toEqual({ i: 1, j: 8 });
|
||||
expect(chunkName(i, j)).toBe("B9");
|
||||
});
|
||||
});
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"pairs": [["A1", 0, 0], ["L1", 11, 0], ["A12", 0, 11], ["L12", 11, 11], ["C10", 2, 9]],
|
||||
"lowercase": [["c10", 2, 9], ["l12", 11, 11]],
|
||||
"invalid": ["M1", "A0", "A13", "A", "10", "", "A01", "B-3", " "]
|
||||
}
|
||||
Reference in new issue
Block a user