File size: 5,085 Bytes
c1eb573
 
 
 
 
 
 
4713899
 
 
 
 
c1eb573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4713899
c1eb573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4713899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d07e5b
c1eb573
 
 
 
 
 
 
 
4713899
 
c1eb573
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""Tests for Myco's core game loop."""

from __future__ import annotations

import unittest

from game.catalog import load_mushrooms
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
from game.progression import current_area, next_area, unlocked_areas
from game.state import EMPTY_DEX, welcome_history
from models.mushroom import Mushroom
from ui.renderers import dex_markdown, mushroom_card, progress_markdown
from game.engine import collect_current, discover_mushroom, myco_reply
from game.state import EMPTY_DEX, welcome_history
from models.mushroom import Mushroom
from ui.renderers import dex_markdown, mushroom_card


class MycoGameLoopTests(unittest.TestCase):
    """Coverage for the first playable Myco loop."""

    def test_catalog_has_mvp_scale_and_rarities(self) -> None:
        mushrooms = load_mushrooms()

        self.assertEqual(len(mushrooms), 30)
        self.assertEqual({mushroom.rarity for mushroom in mushrooms}, {"Common", "Rare", "Legendary"})

    def test_discover_mushroom_returns_current_state_and_myco_prompt(self) -> None:
        glowcap = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.")

        mushroom, current, history = discover_mushroom([], catalog=[glowcap])

        self.assertEqual(mushroom, glowcap)
        self.assertEqual(current["name"], "Glowcap")
        self.assertEqual(history[0], {"role": "assistant", "content": "Hello! I'm Myco. Let's explore the forest."})
        self.assertIn("We found a Glowcap", history[1]["content"])
        self.assertIn("eat, collect, or study", history[1]["content"])

    def test_myco_reply_comments_on_current_mushroom(self) -> None:
        current = Mushroom(
            "Glowcap",
            "Common",
            "mossy logs",
            "I think this one glows at night, but I'm not completely sure.",
        ).to_dict()

        prompt, history = myco_reply("What is it?", welcome_history(), current)

        self.assertEqual(prompt, "")
        self.assertEqual(history[-1]["role"], "assistant")
        self.assertIn("I think this is **Glowcap**", history[-1]["content"])
        self.assertIn("not completely sure", history[-1]["content"])

    def test_collect_current_adds_once(self) -> None:
        current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict()

        collection, history = collect_current(current, [], welcome_history())
        second_collection, second_history = collect_current(current, collection, history)

        self.assertEqual([entry["name"] for entry in collection], ["Glowcap"])
        self.assertEqual(second_collection, collection)
        self.assertIn("already safe", second_history[-1]["content"])

    def test_study_current_reveals_magic_hint(self) -> None:
        current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict()

        studied, history = study_current(current, welcome_history())

        self.assertIsNotNone(studied)
        assert studied is not None
        self.assertEqual(studied["magic"], "Tiny spore shimmer")
        self.assertEqual(studied["studied"], "Yes")
        self.assertIn("New MycoDex note", history[-1]["content"])

    def test_eat_current_keeps_unknown_mushrooms_safe(self) -> None:
        current = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.").to_dict()

        history = eat_current(current, welcome_history())

        self.assertIn("gently blocks", history[-1]["content"])
        self.assertIn("instead of eating", history[-1]["content"])

    def test_progression_unlocks_areas_by_collection_count(self) -> None:
        self.assertEqual(current_area(0).name, "Mossy Trail")
        self.assertEqual(next_area(0).name, "Crystal Grove")
        self.assertEqual(current_area(10).name, "Crystal Grove")
        self.assertEqual(next_area(25).name, "Mushroom Elder")
        self.assertEqual([area.name for area in unlocked_areas(25)], ["Mossy Trail", "Crystal Grove", "Moonlit Cavern"])

    def test_renderers_show_unknown_traits_progress_and_empty_dex(self) -> None:
        mushroom = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.")

        card = mushroom_card(mushroom)
        progress = progress_markdown([])
        
    def test_renderers_show_unknown_traits_and_empty_dex(self) -> None:
        mushroom = Mushroom("Glowcap", "Common", "mossy logs", "I think this one glows at night, but I'm not completely sure.")

        card = mushroom_card(mushroom)

        self.assertIn("**Edible:** Unknown", card)
        self.assertIn("**Magic:** Unknown", card)
        self.assertIn("**Danger:** Unknown", card)
        self.assertIn("Forest Progress", progress)
        self.assertIn("Crystal Grove", progress)
        self.assertEqual(dex_markdown([]), EMPTY_DEX)


if __name__ == "__main__":
    unittest.main()