- Introduce CharacterState value object to group character properties → Character constructor reduced from 5 to 1 parameter - Introduce Faction value type (previously bare string) - Remove cross-story methods: isAllyOf, isAlive, isDead, add, isMax, next, diff - Remove misleading level parameter from Health.create - Remove trivial invariant tests (dead-code paths on fresh characters) - Move cross-cutting invariants out of character-creation.allium - ESLint: forbid unused params (remove argsIgnorePattern), max-params=5 - null parameters enforced by TypeScript strictNullChecks (tsconfig)
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import fc from 'fast-check';
|
|
import { describe, it } from 'vitest';
|
|
import { Character } from './Character.ts';
|
|
import { Level } from './Level.ts';
|
|
|
|
describe('CharacterCreation', () => {
|
|
describe('initial health', () => {
|
|
it('property: new character has health 1000', () => {
|
|
fc.assert(
|
|
fc.property(fc.string({ minLength: 1, maxLength: 50 }), (name) => {
|
|
const c = Character.create({ name, level: Level.create(1) });
|
|
return c.health.value === 1000;
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('property: health is always 1000 at creation regardless of level', () => {
|
|
fc.assert(
|
|
fc.property(
|
|
fc.string({ minLength: 1, maxLength: 50 }),
|
|
fc.integer({ min: 1, max: 10 }),
|
|
(name, level) => {
|
|
const c = Character.create({ name, level: Level.create(level) });
|
|
return c.health.value === 1000;
|
|
},
|
|
),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('initial status', () => {
|
|
it('property: new character is always alive', () => {
|
|
fc.assert(
|
|
fc.property(fc.string({ minLength: 1, maxLength: 50 }), (name) => {
|
|
const c = Character.create({ name, level: Level.create(1) });
|
|
return c.status.kind === 'alive';
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('initial level', () => {
|
|
it('property: character stores the level given at creation', () => {
|
|
fc.assert(
|
|
fc.property(
|
|
fc.string({ minLength: 1, maxLength: 50 }),
|
|
fc.integer({ min: 1, max: 10 }),
|
|
(name, level) => {
|
|
const c = Character.create({ name, level: Level.create(level) });
|
|
return c.level.value === level;
|
|
},
|
|
),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('initial factions', () => {
|
|
it('property: new character belongs to no factions', () => {
|
|
fc.assert(
|
|
fc.property(fc.string({ minLength: 1, maxLength: 50 }), (name) => {
|
|
const c = Character.create({ name, level: Level.create(1) });
|
|
return c.factions.size === 0;
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
});
|