Files
bworld/tests/carvers_test.ts
T
2026-11-13 20:02:38 -03:00

28 lines
1.2 KiB
TypeScript

// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assert, assertEquals } from "@std/assert";
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { carve_chunk } from "@/common/worldgen/carvers.ts";
import { WorldShape } from "@/common/world_shape.ts";
const shape = new WorldShape({ min_y: -64, max_y: 320, sky_light: true });
const carvers = [{ probability: 1, min_y: 0, max_y: 40 }];
Deno.test("carvers cut tunnels that carry on across chunk borders", () => {
assertEquals(carve_chunk("seed", [], 0, 0, shape), undefined, "no carvers, nothing to cut");
const west = carve_chunk("seed", carvers, 0, 0, shape)!;
const east = carve_chunk("seed", carvers, 1, 0, shape)!;
assertEquals(west, carve_chunk("seed", carvers, 0, 0, shape), "same chunk, same tunnels");
// a cell on the border cut in both chunks
let joined = false;
for (let y = 0; y < shape.height; y++) {
for (let z = 0; z < CHUNK_SIZE; z++) {
const row = y * CHUNK_AREA + z * CHUNK_SIZE;
if (west[row + CHUNK_SIZE - 1] && east[row]) joined = true;
}
}
assert(joined, "a tunnel crosses from one chunk into the next");
assert(west.subarray(0, CHUNK_AREA).every((cut) => !cut), "the world's bottom layer stays");
});