[engine] PlanetGarden: How many weeds and petals a day shows; the gesture recognisers
This commit is contained in:
@@ -8,3 +8,4 @@ export {
|
||||
goodMoment, newOpened, openedIdentity, PETAL, petalAt, petalOrder, sentenceOpened, type PetalNow, type PetalSentence
|
||||
} from './petal/petal.js';
|
||||
export { touch, TOUCH, UNTOUCHED, type TouchReply, type TouchState } from './touch/touch.js';
|
||||
export { petalsToday, weedsToday } from './scene/scene.js';
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* What the planet garden shows of her day (.agents/features/planet-garden.md G3). Pure: the
|
||||
* rose's key and the local day are parameters, so a replay shows the same weeds every time.
|
||||
*/
|
||||
import { petalsOn, seeded, weedsOn } from '../rose/rose.js';
|
||||
import type { LocalDay } from '../time/localDay.js';
|
||||
|
||||
/** How many weeds came up in the night: 2–4 on a day with weeds, else none. */
|
||||
export function weedsToday(seed: string, day: LocalDay): number {
|
||||
return weedsOn(seed, day) ? 2 + Math.floor(seeded(seed, day, 'weed-count') * 3) : 0;
|
||||
}
|
||||
|
||||
/** How many of her petals have fallen: 3–5 on a day with fallen petals, else none. */
|
||||
export function petalsToday(seed: string, day: LocalDay): number {
|
||||
return petalsOn(seed, day) ? 3 + Math.floor(seeded(seed, day, 'petal-count') * 3) : 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { petalsOn, weedsOn } from '../src/rose/rose.js';
|
||||
import { petalsToday, weedsToday } from '../src/scene/scene.js';
|
||||
import { addDays } from '../src/time/localDay.js';
|
||||
|
||||
const KEY = 'K'.repeat(43);
|
||||
const days = Array.from({ length: 120 }, (_, i) => addDays('2026-01-01', i));
|
||||
|
||||
describe('what the planet garden shows of her day (planet-garden.md G3)', () => {
|
||||
it('weeds: none on a day without, 2–4 on a day with', () => {
|
||||
for (const day of days) {
|
||||
const n = weedsToday(KEY, day);
|
||||
expect(n === 0 ? !weedsOn(KEY, day) : weedsOn(KEY, day) && n >= 2 && n <= 4).toBe(true);
|
||||
}
|
||||
expect(new Set(days.map((d) => weedsToday(KEY, d)).filter(Boolean)).size).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it('fallen petals: none on a day without, 3–5 on a day with', () => {
|
||||
for (const day of days) {
|
||||
const n = petalsToday(KEY, day);
|
||||
expect(n === 0 ? !petalsOn(KEY, day) : petalsOn(KEY, day) && n >= 3 && n <= 5).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('property: the same rose on the same day always shows the same count', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.stringMatching(/^[A-Za-z0-9_-]{43}$/), fc.integer({ min: 0, max: 3000 }), (key, offset) => {
|
||||
const day = addDays('2026-01-01', offset);
|
||||
expect(weedsToday(key, day)).toBe(weedsToday(key, day));
|
||||
expect(petalsToday(key, day)).toBe(petalsToday(key, day));
|
||||
}),
|
||||
{ numRuns: 200 }
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user