Skip to content

Commit

Permalink
maximize test coverage of living/status
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelprograms committed Feb 9, 2025
1 parent c85a804 commit 7d30a08
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
29 changes: 29 additions & 0 deletions lib/std/living/status.mock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
inherit "/std/shadow.c";

int *MockHeals = ({ });
void reset_mock_heals () {
MockHeals = ({ });
}
int *query_mock_heals () {
return MockHeals;
}
void heal (int n) {
MockHeals += ({ n });
}

mapping MockAddVitals = ([ "hp": 0, "sp": 0, "mp": 0 ]);
void reset_mock_add_vitals () {
MockAddVitals = ([ "hp": 0, "sp": 0, "mp": 0 ]);
}
mapping query_mock_add_vitals () {
return MockAddVitals;
}
void add_hp (int n) {
MockAddVitals["hp"] += n;
}
void add_sp (int n) {
MockAddVitals["sp"] += n;
}
void add_mp (int n) {
MockAddVitals["mp"] += n;
}
45 changes: 40 additions & 5 deletions lib/std/living/status.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ inherit M_TEST;
* @var {"/std/living/status"} testOb
*/

#define STATUS_MOCK "/std/living/status.c" & "/std/living/status.mock.c"

void test_busy () {
expect("busy should be settable and queryable", (: ({
assert_equal(testOb->query_busy(), 0),
Expand Down Expand Up @@ -73,6 +75,8 @@ void test_immobile () {
}

void test_posture () {
object mockBody;

expect("posture should be settable and queryable", (: ({
assert_equal(testOb->query_posture(), "standing"),

Expand All @@ -86,11 +90,42 @@ void test_posture () {
assert_catch((: testOb->set_posture("unknown") :), "*Bad argument 1 to status->set_posture\n"),
}) :));

// @TODO
// expect("postures should heal on heartbeat", (: ({
// resting
mockBody = new("/std/living/status.mock.c");
mockBody->start_shadow(testOb);
expect("postures should adjust vitals on heart_beat", (: ({
// sitting
testOb->set_posture("sitting"),
assert_equal(testOb->query_posture(), "sitting"),
testOb->heart_beat(),
assert_equal(/** @type {STATUS_MOCK} */ (testOb)->query_mock_heals(), ({ 1 })),
/** @type {STATUS_MOCK} */ (testOb)->reset_mock_heals(),

// laying
testOb->set_posture("laying"),
assert_equal(testOb->query_posture(), "laying"),
testOb->heart_beat(),
assert_equal(/** @type {STATUS_MOCK} */ (testOb)->query_mock_heals(), ({ 2 })),
/** @type {STATUS_MOCK} */ (testOb)->reset_mock_heals(),

// sleeping
// meditating
testOb->set_posture("meditating"),
assert_equal(testOb->query_posture(), "meditating"),
testOb->heart_beat(),
assert_equal(/** @type {STATUS_MOCK} */ (testOb)->query_mock_heals(), ({ 2 })),
/** @type {STATUS_MOCK} */ (testOb)->reset_mock_heals(),
// verify we gain mp
assert_equal(/** @type {STATUS_MOCK} */ (testOb)->query_mock_add_vitals()["mp"] > 0, 1),
/** @type {STATUS_MOCK} */ (testOb)->query_mock_add_vitals(),

// flying
testOb->set_posture("flying"),
assert_equal(testOb->query_posture(), "flying"),
testOb->heart_beat(),
// verify we lost sp
assert_equal(/** @type {STATUS_MOCK} */ (testOb)->query_mock_add_vitals()["sp"] < 0, 1),
/** @type {STATUS_MOCK} */ (testOb)->query_mock_add_vitals(),
}) :));

// }) :));
mockBody->stop_shadow();
if (mockBody) destruct(mockBody);
}

0 comments on commit 7d30a08

Please sign in to comment.