|
2 | 2 |
|
3 | 3 | from dnd_character import Character, modifier
|
4 | 4 |
|
5 |
| - |
6 | 5 | # Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
|
7 | 6 |
|
8 |
| -class DnDCharacterTest(unittest.TestCase): |
9 |
| - def test_modifier_for_score_3_is_n4(self): |
| 7 | + |
| 8 | +class DndCharacterTest(unittest.TestCase): |
| 9 | + def test_ability_modifier_for_score_3_is_n4(self): |
10 | 10 | self.assertEqual(modifier(3), -4)
|
11 | 11 |
|
12 |
| - def test_modifier_for_score_4_is_n3(self): |
| 12 | + def test_ability_modifier_for_score_4_is_n3(self): |
13 | 13 | self.assertEqual(modifier(4), -3)
|
14 | 14 |
|
15 |
| - def test_modifier_for_score_5_is_n3(self): |
| 15 | + def test_ability_modifier_for_score_5_is_n3(self): |
16 | 16 | self.assertEqual(modifier(5), -3)
|
17 | 17 |
|
18 |
| - def test_modifier_for_score_6_is_n2(self): |
| 18 | + def test_ability_modifier_for_score_6_is_n2(self): |
19 | 19 | self.assertEqual(modifier(6), -2)
|
20 | 20 |
|
21 |
| - def test_modifier_for_score_7_is_n2(self): |
| 21 | + def test_ability_modifier_for_score_7_is_n2(self): |
22 | 22 | self.assertEqual(modifier(7), -2)
|
23 | 23 |
|
24 |
| - def test_modifier_for_score_8_is_n1(self): |
| 24 | + def test_ability_modifier_for_score_8_is_n1(self): |
25 | 25 | self.assertEqual(modifier(8), -1)
|
26 | 26 |
|
27 |
| - def test_modifier_for_score_9_is_n1(self): |
| 27 | + def test_ability_modifier_for_score_9_is_n1(self): |
28 | 28 | self.assertEqual(modifier(9), -1)
|
29 | 29 |
|
30 |
| - def test_modifier_for_score_10_is_0(self): |
| 30 | + def test_ability_modifier_for_score_10_is_0(self): |
31 | 31 | self.assertEqual(modifier(10), 0)
|
32 | 32 |
|
33 |
| - def test_modifier_for_score_11_is_0(self): |
| 33 | + def test_ability_modifier_for_score_11_is_0(self): |
34 | 34 | self.assertEqual(modifier(11), 0)
|
35 | 35 |
|
36 |
| - def test_modifier_for_score_12_is_1(self): |
| 36 | + def test_ability_modifier_for_score_12_is_1(self): |
37 | 37 | self.assertEqual(modifier(12), 1)
|
38 | 38 |
|
39 |
| - def test_modifier_for_score_13_is_1(self): |
| 39 | + def test_ability_modifier_for_score_13_is_1(self): |
40 | 40 | self.assertEqual(modifier(13), 1)
|
41 | 41 |
|
42 |
| - def test_modifier_for_score_14_is_2(self): |
| 42 | + def test_ability_modifier_for_score_14_is_2(self): |
43 | 43 | self.assertEqual(modifier(14), 2)
|
44 | 44 |
|
45 |
| - def test_modifier_for_score_15_is_2(self): |
| 45 | + def test_ability_modifier_for_score_15_is_2(self): |
46 | 46 | self.assertEqual(modifier(15), 2)
|
47 | 47 |
|
48 |
| - def test_modifier_for_score_16_is_3(self): |
| 48 | + def test_ability_modifier_for_score_16_is_3(self): |
49 | 49 | self.assertEqual(modifier(16), 3)
|
50 | 50 |
|
51 |
| - def test_modifier_for_score_17_is_3(self): |
| 51 | + def test_ability_modifier_for_score_17_is_3(self): |
52 | 52 | self.assertEqual(modifier(17), 3)
|
53 | 53 |
|
54 |
| - def test_modifier_for_score_18_is_4(self): |
| 54 | + def test_ability_modifier_for_score_18_is_4(self): |
55 | 55 | self.assertEqual(modifier(18), 4)
|
56 | 56 |
|
57 | 57 | def test_random_ability_is_within_range(self):
|
58 |
| - self.assertIn(Character().ability(), range(3, 19)) |
| 58 | + score = Character().ability() |
| 59 | + self.assertIs(score >= 3 and score <= 18, True) |
59 | 60 |
|
60 | 61 | def test_random_character_is_valid(self):
|
61 | 62 | Char = Character()
|
62 |
| - self.assertIn(Char.strength, range(3, 19)) |
63 |
| - self.assertIn(Char.dexterity, range(3, 19)) |
64 |
| - self.assertIn(Char.constitution, range(3, 19)) |
65 |
| - self.assertIn(Char.intelligence, range(3, 19)) |
66 |
| - self.assertIn(Char.wisdom, range(3, 19)) |
67 |
| - self.assertIn(Char.charisma, range(3, 19)) |
68 |
| - self.assertEqual( |
69 |
| - Char.hitpoints, |
70 |
| - 10 + modifier(Char.constitution)) |
| 63 | + self.assertIs(Char.strength >= 3 and Char.strength <= 18, True) |
| 64 | + self.assertIs(Char.dexterity >= 3 and Char.dexterity <= 18, True) |
| 65 | + self.assertIs(Char.constitution >= 3 and Char.constitution <= 18, True) |
| 66 | + self.assertIs(Char.intelligence >= 3 and Char.intelligence <= 18, True) |
| 67 | + self.assertIs(Char.wisdom >= 3 and Char.wisdom <= 18, True) |
| 68 | + self.assertIs(Char.charisma >= 3 and Char.charisma <= 18, True) |
| 69 | + self.assertIs(Char.hitpoints == 10 + modifier(Char.constitution), True) |
71 | 70 |
|
72 | 71 | def test_each_ability_is_only_calculated_once(self):
|
73 | 72 | Char = Character()
|
74 |
| - self.assertEqual(Char.strength, Char.strength) |
| 73 | + self.assertIs(Char.strength == Char.strength, True) |
75 | 74 |
|
76 | 75 |
|
77 |
| -if __name__ == '__main__': |
| 76 | +if __name__ == "__main__": |
78 | 77 | unittest.main()
|
0 commit comments