MVP checks / mvp (push) Waiting to run
Add shared Rust/WASM physics, worker meshing and diagnostics, 64-chunk full-height streaming, atlas texture support, and baseline world import. Document the current implementation and include the supplied in-game lobby screenshot.
99 lines
3.5 KiB
JavaScript
99 lines
3.5 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { SectionBlockMap } from "../section-block-map.js";
|
|
|
|
test("construction and repeated set preserve Map behavior and unique section keys", () => {
|
|
const blocks = new SectionBlockMap([
|
|
["0,0,0", 1],
|
|
["15,15,15", 2],
|
|
["16,0,0", 3],
|
|
["0,0,0", 4],
|
|
]);
|
|
assert.ok(blocks instanceof Map);
|
|
assert.equal(blocks.size, 3);
|
|
assert.equal(blocks.set("0,0,0", 5), blocks);
|
|
assert.deepEqual(
|
|
[...blocks],
|
|
[
|
|
["0,0,0", 5],
|
|
["15,15,15", 2],
|
|
["16,0,0", 3],
|
|
],
|
|
);
|
|
assert.deepEqual([...blocks.keysInSection("0,0,0")], ["0,0,0", "15,15,15"]);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], ["0,0,0", "1,0,0"]);
|
|
assert.deepEqual([...new SectionBlockMap(blocks)], [...blocks]);
|
|
});
|
|
|
|
test("section boundaries use floor division independently on negative axes", () => {
|
|
const blocks = new SectionBlockMap([
|
|
["-1,-16,-17", 1],
|
|
["-16,-1,-32", 2],
|
|
["-17,0,16", 3],
|
|
["0,-17,-1", 4],
|
|
]);
|
|
assert.deepEqual(
|
|
[...blocks.keysInSection("-1,-1,-2")],
|
|
["-1,-16,-17", "-16,-1,-32"],
|
|
);
|
|
assert.deepEqual([...blocks.keysInSection("-2,0,1")], ["-17,0,16"]);
|
|
assert.deepEqual([...blocks.keysInSection("0,-2,-1")], ["0,-17,-1"]);
|
|
assert.deepEqual([...blocks.keysInSection("0,0,0")], []);
|
|
});
|
|
|
|
test("delete removes empty sections and clear permits clean reuse", () => {
|
|
const blocks = new SectionBlockMap([
|
|
["0,0,0", 1],
|
|
["1,0,0", 2],
|
|
["16,0,0", 3],
|
|
]);
|
|
assert.equal(blocks.delete("0,0,0"), true);
|
|
assert.equal(blocks.delete("0,0,0"), false);
|
|
assert.deepEqual([...blocks.keysInSection("0,0,0")], ["1,0,0"]);
|
|
assert.equal(blocks.delete("1,0,0"), true);
|
|
assert.deepEqual([...blocks.keysInSection("0,0,0")], []);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], ["1,0,0"]);
|
|
assert.equal(blocks.clear(), undefined);
|
|
assert.equal(blocks.size, 0);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], []);
|
|
assert.deepEqual([...blocks.keysInSection("1,0,0")], []);
|
|
blocks.set("0,0,0", 4);
|
|
assert.deepEqual([...blocks.keysInSection("0,0,0")], ["0,0,0"]);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], ["0,0,0"]);
|
|
});
|
|
|
|
test("section key iterators allow deleting every yielded block without skipping", () => {
|
|
const blocks = new SectionBlockMap([
|
|
["0,0,0", 1],
|
|
["1,0,0", 2],
|
|
["2,0,0", 3],
|
|
["16,0,0", 4],
|
|
]);
|
|
for (const key of blocks.keysInSection("0,0,0")) blocks.delete(key);
|
|
assert.deepEqual([...blocks], [["16,0,0", 4]]);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], ["1,0,0"]);
|
|
});
|
|
|
|
test("validated section insertion and bulk deletion preserve other sections and live iterators", () => {
|
|
const blocks = new SectionBlockMap([["0,0,0", 1]]);
|
|
assert.equal(blocks.setInSection("-17,-1,16", 2, "-2,-1,1"), blocks);
|
|
blocks.setInSection("-18,-2,17", 3, "-2,-1,1");
|
|
blocks.setInSection("-17,-1,16", 4, "-2,-1,1");
|
|
assert.deepEqual(
|
|
[...blocks.keysInSection("-2,-1,1")],
|
|
["-17,-1,16", "-18,-2,17"],
|
|
);
|
|
const keys = blocks.keysInSection("-2,-1,1");
|
|
assert.equal(blocks.deleteSection("-2,-1,1"), 2);
|
|
assert.equal(blocks.deleteSection("-2,-1,1"), 0);
|
|
assert.deepEqual([...keys], []);
|
|
assert.deepEqual([...blocks], [["0,0,0", 1]]);
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], ["0,0,0"]);
|
|
blocks.set("-17,-1,16", 5);
|
|
assert.deepEqual([...blocks.keysInSection("-2,-1,1")], ["-17,-1,16"]);
|
|
assert.equal(blocks.delete("-17,-1,16"), true);
|
|
blocks.setInSection("16,0,0", 6, "1,0,0");
|
|
blocks.clear();
|
|
assert.deepEqual([...blocks.loadedSectionKeys()], []);
|
|
});
|