From 91d32a71ee530ddb02a413e423af918858e03e57 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 25 Feb 2026 10:32:55 -0500 Subject: [PATCH] Add campfireRest function with tests --- src/run.js | 4 ++++ src/run.test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/run.js b/src/run.js index cfc6a6d..84db902 100644 --- a/src/run.js +++ b/src/run.js @@ -23,6 +23,10 @@ export function endCombat(run, combatHp) { return { ...run, hp, combatCount: run.combatCount + 1 }; } +export function campfireRest(run) { + return { ...run, hp: Math.min(run.hp + 3, run.maxHp) }; +} + export function revealRewards(run) { const count = Math.min(3, run.cardRewardsDeck.length); const revealed = run.cardRewardsDeck.slice(0, count); diff --git a/src/run.test.js b/src/run.test.js index b872066..a5bf0dd 100644 --- a/src/run.test.js +++ b/src/run.test.js @@ -2,6 +2,7 @@ import { beforeAll, describe, expect, test } from "bun:test"; import { getAllCards, initCards } from "./cards.js"; import { initEnemies } from "./enemies.js"; import { + campfireRest, createRunState, endCombat, pickReward, @@ -89,6 +90,20 @@ describe("endCombat", () => { }); }); +describe("campfireRest", () => { + test("campfireRest heals 3 HP", () => { + const run = { hp: 5, maxHp: 11 }; + const result = campfireRest(run); + expect(result.hp).toBe(8); + }); + + test("campfireRest does not heal above maxHp", () => { + const run = { hp: 10, maxHp: 11 }; + const result = campfireRest(run); + expect(result.hp).toBe(11); + }); +}); + describe("rewards", () => { test("revealRewards removes 3 from rewards deck and returns them", () => { const run = createRunState("ironclad");