diff options
| author | Bobby <[email protected]> | 2026-04-22 09:53:17 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-04-22 09:53:17 +0530 |
| commit | aaf299374d767d38f532d148bd0b5d89db4e6574 (patch) | |
| tree | 550a51b58cd417a124ff513fd2dc16c9802ed33f /tests | |
| parent | 8877f532599011ca02f267863189d4ffe6755955 (diff) | |
| download | hollowdark-aaf299374d767d38f532d148bd0b5d89db4e6574.tar.xz hollowdark-aaf299374d767d38f532d148bd0b5d89db4e6574.zip | |
Generate a fresh year-1111 world on Begin and persist it to the user-data database
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/worldgen/world.test.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/unit/worldgen/world.test.ts b/tests/unit/worldgen/world.test.ts new file mode 100644 index 0000000..7f7e0ce --- /dev/null +++ b/tests/unit/worldgen/world.test.ts @@ -0,0 +1,48 @@ +import { describe, expect, test } from 'vitest' + +import type { WorldId } from '@hollowdark/engine/entities/base' +import { FIRST_EVER_YEAR, generateWorld } from '@hollowdark/worldgen/world' + +const FIXED_ID = 'test-world-1111' as WorldId +const FIXED_SEED = 'test-seed-1111' +const FIXED_CREATED_AT = '2026-04-22T09:00:00.000Z' + +describe('generateWorld', () => { + test('lands at year 1111, Thawing 1', () => { + const world = generateWorld({ id: FIXED_ID, seed: FIXED_SEED, createdAt: FIXED_CREATED_AT }) + expect(world.currentGameTime).toEqual({ + year: FIRST_EVER_YEAR, + month: 1, + day: 1, + tickOfDay: 0 + }) + }) + + test('starts with no characters, no events, no crisis', () => { + const world = generateWorld({ id: FIXED_ID, seed: FIXED_SEED, createdAt: FIXED_CREATED_AT }) + expect(world.currentPlayerCharacterId).toBeNull() + expect(world.playedCharacterIds).toEqual([]) + expect(world.tierOneIds).toEqual([]) + expect(world.tierTwoIds).toEqual([]) + expect(world.activeEventIds).toEqual([]) + expect(world.scheduledEvents).toEqual([]) + expect(world.crisisState.active).toBe(false) + expect(world.politicsByRegion.size).toBe(0) + }) + + test('seeded generation is deterministic given fixed inputs', () => { + const a = generateWorld({ id: FIXED_ID, seed: FIXED_SEED, createdAt: FIXED_CREATED_AT }) + const b = generateWorld({ id: FIXED_ID, seed: FIXED_SEED, createdAt: FIXED_CREATED_AT }) + expect(a).toEqual(b) + }) + + test('defaults the seed to the generated id when only id is provided', () => { + const world = generateWorld({ id: FIXED_ID, createdAt: FIXED_CREATED_AT }) + expect(world.seed).toBe(FIXED_ID) + }) + + test('records the current schema version in settings', () => { + const world = generateWorld({ id: FIXED_ID, seed: FIXED_SEED, createdAt: FIXED_CREATED_AT }) + expect(world.settings.schemaVersion).toBe(1) + }) +}) |
