seedmarkfile
seedmark/tests/recipe.test.js/

tests/recipe.test.js raw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import * as api from '../src/index.js';
4const families = ['masks', 'creatures', 'botanical', 'orbital', 'landscapes', 'glyphs', 'woven', 'machines'];
5const frozen = value => value && typeof value === 'object' && Object.isFrozen(value) && Object.values(value).every(v => v === null || typeof v !== 'object' || frozen(v));
6test('recipes are deeply frozen plain data with all eight stable families and independent layers', () => {
7 assert.equal(typeof api.recipe, 'function');
8 assert.equal(api.VERSION, 1);
9 assert.deepEqual(api.FAMILIES, families);
10 assert(Object.isFrozen(api.FAMILIES));
11 const seen = new Set();
12 for (let i = 0; i < 512; i++) {
13 const seed = `recipe-${i}`;
14 const r = api.recipe(seed);
15 seen.add(r.family);
16 assert.deepEqual(r, api.recipe(seed));
17 assert.deepEqual(r, JSON.parse(JSON.stringify(r)));
18 assert(frozen(r));
19 assert.equal(r.version, 1);
20 assert.equal(r.family, api.createRng(seed, 'family').pick(families));
21 assert.equal(r.layout.variant, api.createRng(seed, 'layout').int(0, 3));
22 assert.equal(r.silhouette.variant, api.createRng(seed, 'silhouette').int(0, 3));
23 assert.equal(r.features.variant, api.createRng(seed, 'features').int(0, 3));
24 assert.equal(r.texture.variant, api.createRng(seed, 'texture').int(0, 2));
25 assert(r.palette.length >= 2 && r.palette.length <= 4);
26 assert(r.palette.every(c => /^#[0-9a-f]{6}$/.test(c)));
27 }
28 assert.deepEqual(seen, new Set(families));
29 for (const s of ['', '😀\u0000', ' arbitrary text ']) assert(frozen(api.recipe(s)));
30});
31test('recipe rejects unsupported versions and nonstring seeds', () => {
32 for (const version of [0, 2, -1, 1.1, '1', null, NaN]) assert.throws(() => api.recipe('s', {version}), RangeError);
33 for (const s of [undefined, 7, {}, null]) assert.throws(() => api.recipe(s), TypeError);
34});

About

ownerba1b5beed5b5
visibilitypublic
headc808a940bc19

Maintainers

  • ba1b5beed5b5 owner

Clone

  • https://012.run/npub1hgd4hmk4kkukjx7yf402adl7msw0ssnmqmt0y6sgz0j8yjjcj9nqh9znde/seedmark.git

Refs