From a14d446e824a1804657ebe957d725a160ff304b7 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 6 Dec 2022 01:40:09 +0100 Subject: [PATCH] Tests roll En vrij grondig ook nog, al zeg ik het zelf --- tests/shitpost.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/shitpost.py b/tests/shitpost.py index 5d734fd..7a4d7a3 100644 --- a/tests/shitpost.py +++ b/tests/shitpost.py @@ -114,3 +114,34 @@ class TestShitpost(unittest.TestCase): self.assertIsInstance(wb_v, str) with self.subTest("Verbose isn't actually verbose"): self.assertTrue(len(wb_v) > len(wb)) + + def test_roll(self): + with self.subTest("Incorrect acceptance of malformed string"): + self.assertIsNone(self.cog.get_dice_parameters("1 d 20 ")) + with self.subTest("Incorrect parsing of capital D"): + self.assertEqual((1, 20, None), self.cog.get_dice_parameters("1D20")) + with self.subTest("Incorrect parsing of die-string"): + self.assertEqual((1, 20, None), self.cog.get_dice_parameters("1d20")) + with self.subTest("Incorrect parsing of die modifier"): + self.assertEqual((2, 20, 3), self.cog.get_dice_parameters("2d20+3")) + with self.subTest("Incorrect parsing of spacing in die-string"): + self.assertEqual((1, 20, 5), self.cog.get_dice_parameters("1d20 + 5")) + with self.subTest("Incorrect parsing of negative modifier"): + self.assertEqual((1, 12, -3), self.cog.get_dice_parameters("1d12 - 3")) + with self.subTest("Incorrect parsing of unbalanced spacing"): + self.assertEqual((1, 12, -3), self.cog.get_dice_parameters("1d12 -3")) + with self.subTest("Incorrect parsing of largest values"): + self.assertEqual((99, 9999, 9999), self.cog.get_dice_parameters("99d9999 + 9999")) + + with self.subTest("Incorrect acceptance of too many dice"): + self.assertIsNone(self.cog.get_dice_roll(100, 20, None)) + with self.subTest("Incorrect acceptance of too big die"): + self.assertIsNone(self.cog.get_dice_roll(4, 10000, None)) + with self.subTest("Incorrect acceptance of too large modifier"): + self.assertIsNone(self.cog.get_dice_roll(1, 20, 999999)) + with self.subTest("Incorrect acceptance of too large negative modifier"): + self.assertIsNone(self.cog.get_dice_roll(1, 20, -999999)) + with self.subTest("Critical fail/success not marked"): + self.assertIn("**10**", self.cog.get_dice_roll(99, 10, None)) + self.assertIn("**1**", self.cog.get_dice_roll(99, 10, None)) + self.assertTrue(True)