-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbattle_test.py
32 lines (26 loc) · 1.07 KB
/
battle_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
""" unit test for battle.py """
from unittest import TestCase, main
from unittest.mock import patch
from player import Player
from arena import attack_rolls
def fixedroller(count, die):
""" this will replace the random die in our test """
return count * max(1, die-2)
class TestBattle(TestCase):
""" unit tests for the dnd5e battle simulator """
@patch('arena.roll', side_effect=fixedroller)
def test_battle(self, mock_roller):
""" test the outcome of a mock battle with a fixed die"""
verbose = False
winner = Player(name="winner", maxhp=30, ac=15, attacks=[[0, 1, 6, 4]])
loser = Player(name="loser", maxhp=20, ac=15, attacks=[[0, 1, 6, 0]])
attack_rolls(winner, loser, verbose)
self.assertEqual(winner.hp, 30)
self.assertEqual(loser.hp, 12)
self.assertEqual(mock_roller.call_count, 2)
attack_rolls(loser, winner, verbose)
self.assertEqual(winner.hp, 26)
self.assertEqual(loser.hp, 12)
self.assertEqual(mock_roller.call_count, 4)
if __name__ == '__main__':
main()