Testing the merchant must handle two cases: the bought item is a heart or not

This commit is contained in:
Yohann D'ANELLO 2020-12-09 17:04:29 +01:00
parent 4dbd4f7912
commit 6d4c0b2ca3

View File

@ -8,7 +8,7 @@ from ..bootstrap import Bootstrap
from ..display.display import Display
from ..display.display_manager import DisplayManager
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 ..enums import DisplayActions
from ..game import Game, KeyValues, GameMode
@ -507,6 +507,8 @@ class TestGame(unittest.TestCase):
self.game.handle_key_pressed(KeyValues.UP)
self.assertEqual(self.game.store_menu.position, 1)
# The second item is not a heart
merchant.inventory[1] = Sword()
# Buy the second item
item = self.game.store_menu.validate()
self.assertIn(item, merchant.inventory)
@ -514,6 +516,18 @@ class TestGame(unittest.TestCase):
self.assertIn(item, self.game.player.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
self.game.handle_key_pressed(KeyValues.SPACE)
self.assertEqual(self.game.state, GameMode.PLAY)