|
4 | 4 |
|
5 | 5 | from numpy import power
|
6 | 6 |
|
7 |
| -from components.ai import BaseAI, HostileEnemy |
| 7 | +from components.ai import BaseAI, HostileEnemy, ConfusedEnemy |
8 | 8 | from components.fighter import Fighter
|
9 | 9 | from components.inventory import Inventory
|
10 | 10 | from entity import Entity, Actor
|
@@ -109,6 +109,53 @@ def test_get_path_to_avoid_entities(self):
|
109 | 109 | self.assertEqual(path, path_should_be)
|
110 | 110 |
|
111 | 111 |
|
| 112 | +class TestConfusedEnemy(unittest.TestCase): |
| 113 | + def test_init(self): |
| 114 | + ''' |
| 115 | + test that the confused enemy can be initized without issues |
| 116 | + ''' |
| 117 | + actor = Actor(ai_cls=HostileEnemy, fighter=Fighter( |
| 118 | + hp=10, defense=10, power=10), inventory=Inventory(capacity=5)) |
| 119 | + ai = ConfusedEnemy( |
| 120 | + entity=actor, previous_ai=HostileEnemy, turns_remaining=5) |
| 121 | + self.assertEqual(ai.previous_ai, HostileEnemy) |
| 122 | + self.assertEqual(ai.turns_remaining, 5) |
| 123 | + |
| 124 | + def test_perform_switch_ai(self): |
| 125 | + ''' |
| 126 | + test that with 0 or less turns remaining the ai switches back |
| 127 | + ''' |
| 128 | + actor = Actor(ai_cls=HostileEnemy, fighter=Fighter( |
| 129 | + hp=10, defense=10, power=10), inventory=Inventory(capacity=5)) |
| 130 | + ai = ConfusedEnemy( |
| 131 | + entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=0) |
| 132 | + actor.ai = ai |
| 133 | + eng = Engine(player=actor) |
| 134 | + gm = GameMap(engine=eng, width=10, height=10) |
| 135 | + actor.parent = gm |
| 136 | + self.assertIsInstance(actor.ai, ConfusedEnemy) |
| 137 | + actor.ai.perform() |
| 138 | + self.assertIsInstance(actor.ai, HostileEnemy) |
| 139 | + |
| 140 | + def test_perform_bump_action(self): |
| 141 | + ''' |
| 142 | + test that with turns remaining the ai will perform a bump action |
| 143 | + in a random direction and reduce the number of turns remaining |
| 144 | + ''' |
| 145 | + actor = Actor(ai_cls=HostileEnemy, fighter=Fighter( |
| 146 | + hp=10, defense=10, power=10), inventory=Inventory(capacity=5)) |
| 147 | + ai = ConfusedEnemy( |
| 148 | + entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=5) |
| 149 | + actor.ai = ai |
| 150 | + eng = Engine(player=actor) |
| 151 | + gm = GameMap(engine=eng, width=10, height=10) |
| 152 | + actor.parent = gm |
| 153 | + with patch('actions.BumpAction.perform') as patch_perform: |
| 154 | + ai.perform() |
| 155 | + self.assertEqual(ai.turns_remaining, 4) |
| 156 | + patch_perform.assert_called_once() |
| 157 | + |
| 158 | + |
112 | 159 | class TestHostileEnemy(unittest.TestCase):
|
113 | 160 | def test_init(self):
|
114 | 161 | '''
|
|
0 commit comments