コード例 #1
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
def testItemCreation():
    items = []
    for _ in range(100):
        swordItem = ItemFactory(ItemList.Sword)
        items.append(swordItem)
        with pytest.raises(Exception):
            swordItem.getTimeLimit()
        assert swordItem.getName() == 'Sword'
コード例 #2
0
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]
コード例 #3
0
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]
コード例 #4
0
 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
コード例 #5
0
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])
コード例 #6
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
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
コード例 #7
0
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()
コード例 #8
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
def testItemConsumed():
    swordItem = ItemFactory(ItemList.Sword)
    numberOfUsesInCreationTime = swordItem.getRemainingUses()
    for _ in range(numberOfUsesInCreationTime):
        assert swordItem.isconsumed() == False
        swordItem.useItem()
    assert swordItem.isconsumed() == True
コード例 #9
0
ファイル: test_character.py プロジェクト: Anatharr/Reseautto
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
コード例 #10
0
ファイル: test_character.py プロジェクト: Anatharr/Reseautto
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)
コード例 #11
0
ファイル: test_character.py プロジェクト: Anatharr/Reseautto
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
コード例 #12
0
ファイル: test_character.py プロジェクト: Anatharr/Reseautto
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()
コード例 #13
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
def testItemNotFound():
    with pytest.raises(Exception):
        item = ItemFactory(ItemList.fakeItem)
コード例 #14
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
def testCoin():
    smallCoin = ItemFactory(ItemList.Coin)
    assert smallCoin.getRemainingUses() == 1
    smallCoin.useItem()
    assert smallCoin.isconsumed() == True
コード例 #15
0
ファイル: test_item.py プロジェクト: Anatharr/Reseautto
def testItemNotUsed():
    swordItem = ItemFactory(ItemList.Sword)
    with pytest.raises(Exception):
        swordItem.getTimeLimit()
    assert swordItem.isUsed() == False
コード例 #16
0
def testRemoveNonexistantItemInBag():
    potion = ItemFactory(ItemList.Potion)
    b = Bag(16,[potion])
    newPotion = ItemFactory(ItemList.Potion)
    assert b.removeItem(newPotion)==False 
コード例 #17
0
ファイル: test_character.py プロジェクト: Anatharr/Reseautto
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,
コード例 #18
0
def testMaxWeightReached():
    b = Bag(10, [ItemFactory(ItemList.Armor) for _ in range(10)])
    assert b.getAllItems()== []