Added tests for dice and equpment parser

This commit is contained in:
bw-mutley
2022-03-30 01:11:22 -03:00
committed by GitHub
parent 94655735e3
commit 8c0322651c
2 changed files with 40 additions and 1 deletions
+21
View File
@@ -233,6 +233,27 @@ class TestCharacter(TestCase):
# Try passing an Armor object directly # Try passing an Armor object directly
char.wield_shield(Shield) char.wield_shield(Shield)
self.assertEqual(char.armor_class, 15) self.assertEqual(char.armor_class, 15)
def test_carrying_weight(self):
char = Character(race="lightfoot halfling", strength=12)
# Check carrying capacity
self.assertEqual(char.carrying_capacity, 180)
# Check the armor weight is included
char.wear_armor(LeatherArmor())
self.assertEqual(char.carrying_weight, 10)
# Check the shield weight is included
char = Character()
char.wield_shield("shield")
self.assertEqual(char.carrying_weight, 6)
# Check the weight weapons at hand are included
char = Character()
char.wield_weapon("shortsword")
char.wield_weapon("dagger")
self.assertEqual(char.carrying_weight, 3)
# Check the listed equipment is included
char = Character()
char.equipment = "blanket, crowbar"
self.assertEqual(char.carrying_weight, 8)
def test_speed(self): def test_speed(self):
# Check that the speed pulls from the character's race # Check that the speed pulls from the character's race
+19 -1
View File
@@ -15,6 +15,11 @@ class TestDice(TestCase):
out = dice.read_dice_str("15d10") out = dice.read_dice_str("15d10")
self.assertEqual(out.faces, 10) self.assertEqual(out.faces, 10)
self.assertEqual(out.num, 15) self.assertEqual(out.num, 15)
# Modifier
out = dice.read_dice_str("2d20 + 5")
self.assertEqual(out.faces, 20)
self.assertEqual(out.num, 2)
self.assertEqual(out.modifier, 5)
# Check a bad value # Check a bad value
with self.assertRaises(DiceError): with self.assertRaises(DiceError):
dice.read_dice_str("Ed15") dice.read_dice_str("Ed15")
@@ -23,7 +28,20 @@ class TestDice(TestCase):
self.assertEqual(dice.combine_dice("1d8 + 6 + 2d8 + 12"), "3d8 + 18") self.assertEqual(dice.combine_dice("1d8 + 6 + 2d8 + 12"), "3d8 + 18")
self.assertEqual(dice.combine_dice("1d8 + 1d5 + 2d8 + 1d5"), "2d5 + 3d8") self.assertEqual(dice.combine_dice("1d8 + 1d5 + 2d8 + 1d5"), "2d5 + 3d8")
def test_dice_mean(self):
dd = dice.read_dice_str("1d10")
dd_mean = dice._dice_mean(dd)
self.assertEqual(dd_mean, 5.5)
dd = dice.read_dice_str("2d20+4")
dd_mean = dice._dice_mean(dd)
self.assertEqual(dd_mean, 25)
def test_dice_roll_mean(self):
dd_mean = dice.dice_roll_mean("1d6")
self.assertEqual(dd_mean, 4)
dd_mean = dice.dice_roll_mean("2d20+2")
self.assertEqual(dd_mean, 23)
def test_simple_rolling(self): def test_simple_rolling(self):
num_tests = 100 num_tests = 100
for _ in range(num_tests): for _ in range(num_tests):