def checkScore(game): score = d.scoreFor(0,game) assert(score == 3) d.updateCoins(0,game,20) d.buyCard(c.province,game) d.endTurn(game) d.updateCoins(0,game,20) d.buyCard(c.duchy,game) score = d.scoreFor(0,game) assert(score == 9) score = d.scoreFor(1,game) assert(score == 6) d.endTurn(game) d.updateCoins(0,game,20) d.buyCard(c.great_hall,game) d.endTurn(game) d.updateCoins(0,game,20) d.buyCard(c.gardens,game) score = d.scoreFor(0,game) assert(score == 10) for i in range(10): d.gainCard(c.silver,game,1,1) score = d.scoreFor(1,game) assert(score == 7) print "TEST CASE PASSED"
def checkPlayCard(game): d.updateCoins(0,game,20) d.buyCard(c.baron,game) d.endTurn(game) d.endTurn(game) assert(d.playCard(-1,0,0,0,game) == -1) for i in range(d.numHandCards(game)): if (d.handCard(0,game) == c.baron): assert(d.playCard(i,1,0,0,game) == 0) else: assert(d.playCard(0,0,0,0,game) == -1) # Still need to refine this print "TEST CASE PASSED"
def test_updateCoins(): maxBonus = random.randint(2,5) maxHandCount = random.randint(2,5) ##kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village] print "TESTING UpdateCoins()" a = d.initializeGame(numPlayers,kingdomCards, randomSeed) assert(a !=-1) for i in range(numPlayers): a.hand[i] = [] for player in range(numPlayers): for handCount in range(1,maxHandCount+1): a.hand[player].append(d.Copper) print a.hand[player] for bonus in range(maxBonus): b = d.updateCoins(player,a,bonus) assert(b ==0) print "TEST PASS" print "Return Value for player: %d, bonus %d and hand count : %d is %d" %(player,bonus, handCount, b) print "Expected value : 0" if (b != 0): print "TEST FAIL" print "Return Value for player: %d, bonus %d and hand count : %d is %d" %(player,bonus, handCount, b) print "Expected value : 0" assert(a.coins == (handCount * 1 + bonus)) print "TEST PASS" print "Testing with all copper coins for player : %d, bonus : %d, handCount : %d, Coin Value = %d" %(player,bonus,handCount,a.coins) print "Expected = %d" %(handCount *1 +bonus) if (a.coins != (handCount * 1 + bonus)): print "TEST FAIL" print "Testing with all copper coins for player : %d, bonus : %d, handCount : %d, Coin Value = %d" %(player,bonus,handCount,a.coins) print "Expected = %d" %(handCount *1 +bonus)
def test_discardCard(): randSeed = 111 numPlayers =random.randint(2,4) kingdomCards = [d.Adventurer, d.Ambassador, d.Baron, d.Council_Room, d.Cutpurse, d.Embargo, d.Feast, d.Gardens, d.Great_Hall, d.Village] card = d.Copper ##random.randint(d.Curse,d.Village) print "TESTING UpdateCoins()" a = d.initializeGame(numPlayers,kingdomCards, randSeed) assert(a !=-1) print "Before discard" print "Card to discard:" print card print "hand before discarding" print a.hand print "Coins available:" print a.coins b = d.discardCard(card,a.whoseTurn,a,0) c = d.updateCoins(a.whoseTurn,a,0) if (b == -1): print "Invalid Input:card not in hand OR SupplyEmpty" assert(b ==0) print "TEST PASS" print "discardCard() is successfull for player : %d discarded %d" %(a.whoseTurn,card) print "After Discarding" print "Card Discarded:" print card print "Hand after Discarding" print a.hand print "Coins Available:" print a.coins
def checkOutpost(game): # Outpost case d.updateCoins(0,game,5) assert(d.buyCard(c.outpost,game) == 0) d.endTurn(game) d.endTurn(game) outpost = -1 for i in range(5): if handCard(i,game) == card.outpost: outpost = i if outpost == -1: d.playCard(outpost,0,0,0,game) d.endTurn(game) assert(d.whoseTurn(game) == 1) assert(d.numHandCards(game) == 3) print "TEST CASE PASSED"
def act50(self): if self.__collectCov: self.__cov.start() try: __result = mydom.updateCoins(self.p_PLAYER[0],self.p_GAME[0],self.p_BONUS[0]) finally: if self.__collectCov: self.__cov.stop() self.__updateCov() __result_REF = otherdom.updateCoins(self.p_PLAYER[0],self.p_GAME_REF[0],self.p_BONUS[0]) assert __result == __result_REF, " (%s) == (%s) " % (__result, __result_REF)