BlueGit

timfa questward

Files

questward / server / tests / nature-noise.test.js

nature-noise.test.js

nature-noise.test.js 833 B Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { natureNoise01, perlin2, NATURE_TINT, NATURE_NOISE_SIZE } from "../../shared/render/natureNoise.js";
4import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
5
6test("nature noise is continuous across chunk borders", () =>
7{
8 const scale = NATURE_TINT.scale;
9 const a = natureNoise01(CHUNK_SIZE - 1, 5, scale);
10 const b = natureNoise01(CHUNK_SIZE, 5, scale);
11 assert.ok(Math.abs(a - b) < 0.25, `border jump too large: ${a} vs ${b}`);
12});
13
14test("perlin is deterministic and bounded", () =>
15{
16 assert.equal(perlin2(1.5, 2.5), perlin2(1.5, 2.5));
17 const n = natureNoise01(12, 34, NATURE_TINT.scale);
18 assert.ok(n >= 0 && n <= 1);
19});
20
21test("nature noise texture includes a one-tile halo", () =>
22{
23 assert.equal(NATURE_NOISE_SIZE, CHUNK_SIZE + 2);
24});