import { describe, expect, it } from "vitest"; import { wantedChunks } from "../src/world/streaming.js"; describe("wantedChunks", () => { it("lädt die Umgebung des Spielers", () => { const { add } = wantedChunks({ x: 0, z: -1000 }, { load: 400, unload: 600, active: new Set() }); expect(add.length).toBeGreaterThan(4); expect(add.length).toBeLessThan(30); }); it("entlädt erst jenseits des größeren Radius", () => { // Chunk 5_5 hat sein Zentrum bei (375, -1125) (SLICE.x0 + 5.5*CHUNK_SIZE, ...). // "near" liegt hier bewusst 500 Einheiten entfernt: außerhalb des Laderadius (400), // aber innerhalb des Entladeradius (600) — genau die Hysterese, die der Testname // behauptet. Der ursprüngliche Brief-Wert {x:1375, z:-1375} traf exakt das Zentrum // von Chunk 9_4 (Distanz zu 5_5: ~1030, weit jenseits von 600) und ließ die eigene // Behauptung "not.toContain" fehlschlagen — siehe Task-8-Report für den RED-Beleg. const active = new Set(["5_5"]); const near = wantedChunks({ x: 875, z: -1125 }, { load: 400, unload: 600, active }); expect(near.remove).not.toContain("5_5"); const far = wantedChunks({ x: -900, z: -2400 }, { load: 400, unload: 600, active }); expect(far.remove).toContain("5_5"); }); it("meldet nichts doppelt an", () => { const active = new Set(wantedChunks({ x: 0, z: -1000 }, { load: 400, unload: 600, active: new Set() }).add); expect(wantedChunks({ x: 0, z: -1000 }, { load: 400, unload: 600, active }).add).toHaveLength(0); }); });