Testing the merchant must handle two cases: the bought item is a heart or not
This commit is contained in:
parent
4dbd4f7912
commit
6d4c0b2ca3
|
@ -8,7 +8,7 @@ from ..bootstrap import Bootstrap
|
||||||
from ..display.display import Display
|
from ..display.display import Display
|
||||||
from ..display.display_manager import DisplayManager
|
from ..display.display_manager import DisplayManager
|
||||||
from ..entities.friendly import Merchant, Sunflower
|
from ..entities.friendly import Merchant, Sunflower
|
||||||
from ..entities.items import Bomb, Sword
|
from ..entities.items import Bomb, Heart, Sword
|
||||||
from ..entities.player import Player
|
from ..entities.player import Player
|
||||||
from ..enums import DisplayActions
|
from ..enums import DisplayActions
|
||||||
from ..game import Game, KeyValues, GameMode
|
from ..game import Game, KeyValues, GameMode
|
||||||
|
@ -507,6 +507,8 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.handle_key_pressed(KeyValues.UP)
|
self.game.handle_key_pressed(KeyValues.UP)
|
||||||
self.assertEqual(self.game.store_menu.position, 1)
|
self.assertEqual(self.game.store_menu.position, 1)
|
||||||
|
|
||||||
|
# The second item is not a heart
|
||||||
|
merchant.inventory[1] = Sword()
|
||||||
# Buy the second item
|
# Buy the second item
|
||||||
item = self.game.store_menu.validate()
|
item = self.game.store_menu.validate()
|
||||||
self.assertIn(item, merchant.inventory)
|
self.assertIn(item, merchant.inventory)
|
||||||
|
@ -514,6 +516,18 @@ class TestGame(unittest.TestCase):
|
||||||
self.assertIn(item, self.game.player.inventory)
|
self.assertIn(item, self.game.player.inventory)
|
||||||
self.assertNotIn(item, merchant.inventory)
|
self.assertNotIn(item, merchant.inventory)
|
||||||
|
|
||||||
|
# Buy a heart
|
||||||
|
merchant.inventory[1] = Heart()
|
||||||
|
item = self.game.store_menu.validate()
|
||||||
|
self.assertIn(item, merchant.inventory)
|
||||||
|
self.assertEqual(item, merchant.inventory[1])
|
||||||
|
self.game.player.health = self.game.player.maxhealth - 1 - item.healing
|
||||||
|
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||||
|
self.assertNotIn(item, self.game.player.inventory)
|
||||||
|
self.assertNotIn(item, merchant.inventory)
|
||||||
|
self.assertEqual(self.game.player.health,
|
||||||
|
self.game.player.maxhealth - 1)
|
||||||
|
|
||||||
# Exit the menu
|
# Exit the menu
|
||||||
self.game.handle_key_pressed(KeyValues.SPACE)
|
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
self.assertEqual(self.game.state, GameMode.PLAY)
|
self.assertEqual(self.game.state, GameMode.PLAY)
|
||||||
|
|
Loading…
Reference in New Issue