Files
h2g2/tests/test_dark.py
seppedl 679639df9f Wire game transitions end-to-end, add Guide lookup, add 79 tests
Transitions:
- Add I-HOUSEWRECK (tick 20) and I-VOGONS (tick 50) timed events to
  earth.py, queued at startup in main.py
- I-VOGONS demolishes Earth and moves player to Vogon Hold
- Fix airlock→Dark transition to call Dark room M-ENTER handler
- Fix dream-restore to support multiple callbacks (list instead of single)
- Add state.finish() call to RAMP for endgame victory

Guide system:
- Add 16-entry lookup database to GUIDE object (space, towel, vogons,
  poetry, beast, babel fish, earth, magrathea, marvin, etc.)
- "consult guide about X" now returns relevant entry text

Tests (79 passing):
- test_engine.py (14): containment, flags, articles, clock mechanics
- test_parser.py (20): directions, compound verbs, prepositions, synonyms
- test_earth.py (21): full opening sequence, puzzles, navigation
- test_vogon.py (4): room existence, Hold first-visit sequence
- test_dark.py (7): inventory clearing, dream dispatch, probabilities
- conftest.py: shared game fixture and send() helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 22:04:22 +02:00

125 lines
3.5 KiB
Python

"""Tests for the DARK dream dispatch room."""
from tests.conftest import send
def test_dark_room_exists(game):
"""Verify the DARK room was registered."""
state, _, _ = game
dark_room = state.world.get_room("DARK")
assert dark_room is not None
assert dark_room.id == "DARK"
def test_dark_entry_clears_inventory(game):
"""Entering the DARK room should strip all inventory items."""
state, _, _ = game
# Give player an item
gown = state.world.get("GOWN")
gown.move_to(state.protagonist)
assert len(state.protagonist.children) > 0
# Enter dark room
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
if dark_room.action:
dark_room.action(state, "M-ENTER")
state.output.flush()
# Inventory should be cleared (items moved to local_globals)
assert len(state.protagonist.children) == 0
def test_dark_entry_sets_dreaming(game):
"""Entering DARK should set the dreaming flag."""
state, _, _ = game
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
if dark_room.action:
dark_room.action(state, "M-ENTER")
state.output.flush()
assert state.dreaming is True
def test_dark_entry_produces_text(game):
"""Entering DARK should display flavor text."""
state, _, _ = game
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
if dark_room.action:
dark_room.action(state, "M-ENTER")
text = state.output.flush()
assert len(text) > 0
def test_dark_dispatch_heart_prob(game):
"""With 100% heart_prob and 0% for others, dispatch should go to ENTRY-BAY."""
state, _, _ = game
state.flags["heart_prob"] = 100
state.flags["vogon_prob"] = 0
state.flags["traal_prob"] = 0
state.flags["fleet_prob"] = 0
# Enter dark room
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
state.lying_down = False
if dark_room.action:
dark_room.action(state, "M-ENTER")
state.output.flush()
# Set ready and trigger dispatch
state.flags["dark_exit_ready"] = True
state.flags["dark_hint_given"] = True
text = send(game, "south")
# Should be dispatched to ENTRY-BAY (Heart of Gold)
assert state.here.id == "ENTRY-BAY"
def test_dark_dispatch_vogon_prob(game):
"""With 100% vogon_prob and 0% for others, dispatch should go to HOLD."""
state, _, _ = game
state.flags["heart_prob"] = 0
state.flags["vogon_prob"] = 100
state.flags["traal_prob"] = 0
state.flags["fleet_prob"] = 0
# Enter dark room
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
state.lying_down = False
if dark_room.action:
dark_room.action(state, "M-ENTER")
state.output.flush()
# Set ready and trigger dispatch
state.flags["dark_exit_ready"] = True
state.flags["dark_hint_given"] = True
text = send(game, "south")
assert state.here.id == "HOLD"
def test_dark_look_shows_pitch_dark(game):
"""Looking in DARK should describe pitch darkness."""
state, _, _ = game
dark_room = state.world.get_room("DARK")
state.here = dark_room
state.protagonist.move_to(dark_room)
if dark_room.action:
dark_room.action(state, "M-ENTER")
state.output.flush()
# Trigger M-LOOK
dark_room.action(state, "M-LOOK")
text = state.output.flush()
assert "pitch dark" in text.lower()