Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import test from "node:test";import assert from "node:assert/strict";import { fresh } from "../web/app/save-format.ts";import { simulateBody } from "../web/app/body.ts";import { HOUR, MIN } from "../web/app/utils.ts";const noon = new Date(2026, 9, 1, 12).getTime();function pet() { const state = fresh(); state.pet = { name: "Mochi", traits: ["sweet", "curious"], color: "cream", toy: "ball", hatched: noon, stage: "baby", }; state.nextPoop = noon + 10 * HOUR; return state;}test("awake and sleeping body rates remain unchanged", () => { const awake = pet(), sleeping = pet(); sleeping.asleep = true; sleeping.stats.energy = 40; simulateBody(awake, noon, noon + HOUR, false); simulateBody(sleeping, noon, noon + HOUR, false); assert.deepEqual(awake.stats, { tummy: 62, fun: 64, energy: 75, clean: 87 }); assert.deepEqual(sleeping.stats, { tummy: 68, fun: 70, energy: 62, clean: 89.5 });});test("sleep pauses grime exposure; awake exposure resumes it", () => { const state = pet(); state.poop = 3; state.grimeSince = noon - 45 * MIN; state.asleep = true; state.stats.energy = 10; simulateBody(state, noon, noon + 20 * MIN, true); assert.equal(state.sick, false); assert.equal(state.grimeSince, noon - 25 * MIN); state.asleep = false; simulateBody(state, noon + 20 * MIN, noon + 40 * MIN, true); assert.equal(state.sick, true);});test("exhaustion and recent wake protection are body rules", () => { const state = pet(); state.stats.energy = 5; state.wokeAt = noon; simulateBody(state, noon, noon + MIN, false); assert.equal(state.asleep, false); const events = simulateBody(state, noon + MIN, noon + 6 * MIN, false); assert.equal(state.asleep, true); assert.ok(events.includes("fell asleep"));});test("a rested pet wakes, and a projection cannot mutate the saved body", () => { const state = pet(); state.asleep = true; state.stats.energy = 98; const projection = structuredClone(state); assert.ok(simulateBody(projection, noon, noon + 10 * MIN, false).includes("woke")); assert.equal(projection.asleep, false); assert.equal(state.asleep, true); assert.equal(state.stats.energy, 98);});