def testItemCreation(): items = [] for _ in range(100): swordItem = ItemFactory(ItemList.Sword) items.append(swordItem) with pytest.raises(Exception): swordItem.getTimeLimit() assert swordItem.getName() == 'Sword'
def testBagCreationAndFailureInAddingItems(): potion = ItemFactory(ItemList.Potion) b = Bag(16,[potion]) assert b.getCurrentWeight() == potion.getWeight() newPotion = ItemFactory(ItemList.Potion) assert b.addItem(newPotion)== False assert b.getCurrentWeight() == potion.getWeight() assert b.getAllItems()== [potion]
def testChooseItemAndRemoveIt(): potion = ItemFactory(ItemList.Potion) coin = ItemFactory(ItemList.Coin) items = [potion, coin] b = Bag(100, items) potionItems = b.getItemsFromType(ItemList.Potion) assert b.getAllItems() == items b.removeItem(potionItems[0]) assert b.getAllItems() == [coin]
def randomItem(self): """ @return random sword or armor for fighter level up """ randType = randrange(2) # 0:Sword 1:Armor if randType == 0: newItem = ItemFactory(ItemList.Sword) else: newItem = ItemFactory(ItemList.Armor) return newItem
def testBalanceInBag(): items = [] coins = [] potion = ItemFactory(ItemList.Potion) items.append(potion) for _ in range(3): coin = ItemFactory(ItemList.Coin) coins.append(coin) items.append(coin) b = Bag(100, items) assert b.getBalance() == sum([coin.getValue() for coin in coins])
def testItemUsed(): potionItem = ItemFactory(ItemList.Potion) numberOfUsesInCreationTime = potionItem.getRemainingUses() potionItem.useItem() assert potionItem.isUsed() == True assert potionItem.getRemainingUses() == numberOfUsesInCreationTime - 1 sleep(2) assert potionItem.getTimeRemaining() < 148
def testBagCreationAndAddingItems(): potion = ItemFactory(ItemList.Potion) b = Bag(100, [potion]) assert b.getCurrentWeight() == potion.getWeight() newPotion = ItemFactory(ItemList.Potion) b.addItem(newPotion) assert b.getCurrentWeight() == potion.getWeight() + newPotion.getWeight()
def testItemConsumed(): swordItem = ItemFactory(ItemList.Sword) numberOfUsesInCreationTime = swordItem.getRemainingUses() for _ in range(numberOfUsesInCreationTime): assert swordItem.isconsumed() == False swordItem.useItem() assert swordItem.isconsumed() == True
def testGetPlayerBag(): potion = ItemFactory(ItemList.Potion) bag = game.inventorywindow.bag player = Player(game, (0, 0), PlayerEnum.Rogue, actionPoint, lineOfSight, defaultStats) player1 = Player(game, (1, 5), PlayerEnum.Fighter, actionPoint, lineOfSight, defaultStats) assert player.getBag() == bag assert player1.getBag() == bag
def test_Player_sellItem(): potion = ItemFactory(ItemList.Potion) player = Player(game, (0, 0), PlayerEnum.Rogue, actionPoint, skills=defaultSkills, stats=defaultStats, lineOfSightRadius=5) npc = NPC(game, (1, 2)) playerBag = player.getBag() playerBag.flush() playerBag.addItem(potion) npcBag = npc.getBag() collectionOfCoins = [ItemFactory(ItemList.Coin) for _ in range(20)] for coin in collectionOfCoins: npcBag.addItem(coin) player.sellItem(ItemList.Potion, npc)
def test_NPC_sellItem(): player = Player(game, (0, 0), PlayerEnum.Rogue, actionPoint, skills=defaultSkills, stats=defaultStats, lineOfSightRadius=5) potion = ItemFactory(ItemList.Potion) npc = NPC(game, (1, 2), [potion]) playerBag = player.getBag() playerBag.flush() npcBag = npc.getBag() collectionOfCoins = [ItemFactory(ItemList.Coin) for _ in range(20)] for coin in collectionOfCoins: playerBag.addItem(coin) npc.sellItem(ItemList.Potion, player) assert len(playerBag.getAllItems()) == len(collectionOfCoins) + 1
def testPlayerEquip(): sword = ItemFactory(ItemList.Sword) armor = ItemFactory(ItemList.Armor) ringL = ItemFactory(ItemList.Ring) ringR2 = ItemFactory(ItemList.Ring) ringR = ItemFactory(ItemList.Ring) necklace = ItemFactory(ItemList.Necklace) potion = ItemFactory(ItemList.Potion) player = Player(game, (0, 0), PlayerEnum.Rogue, actionPoint, skills=defaultSkills, stats=defaultStats, lineOfSightRadius=5) currentStats = dict(player.listStat) player.equip(potion) assert player.listStat == currentStats assert player.equipment == [None, None, None, None, None] player.getBag().flush() player.getBag().addItem(sword) player.getBag().addItem(necklace) player.getBag().addItem(ringR) player.getBag().addItem(ringL) player.getBag().addItem(ringR2) player.getBag().addItem(armor) player.equip(sword) player.equip(ringL) player.equip(necklace) player.equip(armor) player.equip(ringR) assert player.listStat != currentStats assert all( player.equipment[i] == item for i, item in enumerate([sword, armor, necklace, ringL, ringR])) items = player.getBag().getAllItems() assert all(i not in items for i in [sword, armor, necklace, ringL, ringR]) player.equip(ringR2) assert all( player.equipment[i] == item for i, item in enumerate([sword, armor, necklace, ringL, ringR2])) assert ringR in player.getBag().getAllItems()
def testItemNotFound(): with pytest.raises(Exception): item = ItemFactory(ItemList.fakeItem)
def testCoin(): smallCoin = ItemFactory(ItemList.Coin) assert smallCoin.getRemainingUses() == 1 smallCoin.useItem() assert smallCoin.isconsumed() == True
def testItemNotUsed(): swordItem = ItemFactory(ItemList.Sword) with pytest.raises(Exception): swordItem.getTimeLimit() assert swordItem.isUsed() == False
def testRemoveNonexistantItemInBag(): potion = ItemFactory(ItemList.Potion) b = Bag(16,[potion]) newPotion = ItemFactory(ItemList.Potion) assert b.removeItem(newPotion)==False
hp = 100 armor = 7 strength = 2 dex = 3 con = 4 intell = 5 wis = 6 cha = 7 skillsPoint = 0 actionPoint = 10 defaultStats = (hp, armor, strength, dex, con, intell, wis, cha ) #( HP, armor, strength, dex, con, intell, wis, cha ) lineOfSight = 9 defaultPotions = ItemFactory(ItemList.Potion) def testCharacterCreation(): Character.ID = 50 character = Character(game, defaultPosition, actionPoint, *defaultStats) assert character.getID() == 50 assert character.getHP( ) == 100 # Cette méthode est redondante avec character.getAttribute(Attributes.HP), il faudrait l'enlever ou alors enlever HP des attributs assert character.getPosition() == defaultPosition assert character.getActionPoint() == 10 for i, attribute in enumerate(Attributes): assert character.getAttribute(attribute) == defaultStats[i] print(defaultStats) fighter = Fighter(game, defaultPosition,
def testMaxWeightReached(): b = Bag(10, [ItemFactory(ItemList.Armor) for _ in range(10)]) assert b.getAllItems()== []