def test_calculate_turn_bad_status_wrong(self): self.player1.currentMove = self.move1 self.player1.save() self.player2.currentMove = self.move2 self.player2.save() self.battle1.status = Battle.WAITING_FOR_PLAYER self.battle1.save() success = calculateTurn(self.battle1) self.assertFalse(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.player3 = Player.objects.get(user=self.user3) self.calculate_turn_sanity() self.battle1.status = Battle.WAITING_FOR_CHOICE self.battle1.save() success = calculateTurn(self.battle1) self.assertFalse(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.player3 = Player.objects.get(user=self.user3) self.calculate_turn_sanity() self.battle1.status = Battle.FINISHED self.battle1.save() success = calculateTurn(self.battle1) self.assertFalse(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.player3 = Player.objects.get(user=self.user3) self.calculate_turn_sanity()
def test_calculate_turn_good_move_away(self): self.player1.currentMove = self.move4 self.player1.save() self.player2.currentMove = self.move2 self.player2.save() self.battle1.status = Battle.CALCULATING self.battle1.save() self.calculate_turn_sanity() success = calculateTurn(self.battle1) self.assertTrue(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.assertEqual(self.battle1.status, Battle.WAITING_FOR_CHOICE) self.assertEqual(self.player1.currentMove, None) self.assertEqual(self.player2.currentMove, None) self.assertEqual(self.player1.lastMove, self.move4) self.assertEqual(self.player2.lastMove, self.move2) self.assertEqual(self.battle1.distance, Battle.LONG) self.assertEqual(self.player1.hp, 70) self.assertEqual(self.player2.hp, 100) self.assertEqual(self.player1.user.profile.wins, 0) self.assertEqual(self.player1.user.profile.losses, 0) self.assertEqual(self.player2.user.profile.wins, 0) self.assertEqual(self.player2.user.profile.losses, 0) self.assertEqual(self.battle1.turnNumber, 2)
def test_calculate_turn_bad_player2_current_move_none(self): self.player1.currentMove = self.move1 self.player1.save() self.battle1.status = Battle.CALCULATING self.battle1.save() success = calculateTurn(self.battle1) self.assertFalse(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.player3 = Player.objects.get(user=self.user3) self.calculate_turn_sanity()
def test_calculate_turn_p1_wins(self): self.player1.currentMove = self.move1 self.player1.hp = 20 self.player1.save() self.player2.currentMove = self.move2 self.player2.save() self.battle1.status = Battle.CALCULATING self.battle1.player1 = self.player2 self.battle1.player2 = self.player1 self.battle1.save() self.assertEqual(self.player1.hp, 20) self.assertEqual(self.player2.hp, 100) self.assertEqual(self.player1.user.profile.wins, 0) self.assertEqual(self.player1.user.profile.losses, 0) self.assertEqual(self.player2.user.profile.wins, 0) self.assertEqual(self.player2.user.profile.losses, 0) self.assertEqual(self.battle1.turnNumber, 1) self.assertEqual(self.battle1.distance, Battle.MEDIUM) success = calculateTurn(self.battle1) self.assertTrue(success) self.player1 = Player.objects.get(user=self.user1) self.player2 = Player.objects.get(user=self.user2) self.player3 = Player.objects.get(user=self.user3) self.assertEqual(self.battle1.status, Battle.FINISHED) self.assertEqual(self.battle1.winner, self.player2) self.assertEqual(self.player1.currentMove, self.move1) self.assertEqual(self.player2.currentMove, self.move2) self.assertEqual(self.player1.hp, 0) self.assertEqual(self.player2.hp, 70) self.assertEqual(self.player1.user.profile.wins, 0) self.assertEqual(self.player1.user.profile.losses, 1) self.assertEqual(self.player2.user.profile.wins, 1) self.assertEqual(self.player2.user.profile.losses, 0) self.assertEqual(self.battle1.turnNumber, 1) self.assertEqual(self.battle1.distance, Battle.MEDIUM)