예제 #1
0
    def test_minimal_rolls1(self):
        """
        Tests that a dice group of one dice and one sides returns zero.
        """
        dice = RollableDice(1, 1)

        self.assertEqual(1, dice.roll())
예제 #2
0
    def test_multipleDice_multiplies(self):
        """
        Tests that quantity of dice is multiplied by the sides when rolling.
        """
        dice = RollableDice(3, 1)

        self.assertEqual(3, dice.roll())
예제 #3
0
    def test_noQuantity_rolls0(self):
        """
        Tests that a dice group of zero dice returns zero.
        """
        dice = RollableDice(0, 6)

        self.assertEqual(0, dice.roll())
예제 #4
0
    def test_noSides_rolls0(self):
        """
        Tests that a dice group of zero sides returns zero.
        """
        dice = RollableDice(1, 0)

        self.assertEqual(0, dice.roll())
예제 #5
0
    def test_empty_rolls0(self):
        """
        Tests that a dice group of zero dice and zero sides returns zero.
        """
        dice = RollableDice(0, 0)

        self.assertEqual(0, dice.roll())
예제 #6
0
    def test_noneSides(self):
        """
        Tests that rolling with no sides returns nothing.
        """
        dice = RollableDice(1, None)

        self.assertIsNone(dice.roll())
예제 #7
0
    def test_noneQuantity(self):
        """
        Tests that rolling with no quantity returns nothing.
        """
        dice = RollableDice(None, 1)

        self.assertIsNone(dice.roll())
예제 #8
0
    def test_negativeSides(self):
        """
        Tests that rolling with negative sides returns nothing.
        """
        dice = RollableDice(1, -1)

        self.assertIsNone(dice.roll())
예제 #9
0
    def test_negativeQuantity(self):
        """
        Tests that rolling with a negative quantity returns nothing.
        """
        dice = RollableDice(-1, 1)

        self.assertIsNone(dice.roll())
예제 #10
0
    def test_singleDie_multipleRoll(self):
        """
        Tests that the result of rolling a die is kept in the expected range.
        """
        dice = RollableDice(1, 6)

        self.assertIsNotNone(dice.roll())
        self.assertIsNotNone(dice.roll())
        self.assertIsNotNone(dice.roll())
예제 #11
0
    def test_singleDie_range(self):
        """
        Tests that the result of rolling a die is kept in the expected range.
        """
        dice = RollableDice(1, 6)

        roll = dice.roll()

        self.assertTrue(roll >= dice.quantity)
        self.assertTrue(roll <= dice.sides)
예제 #12
0
    def test_multipleDie_range(self):
        """
        Tests that the result of rolling multiple dice is kept in the expected
        range.
        """
        dice = RollableDice(3, 6)

        roll = dice.roll()

        self.assertTrue(roll >= dice.quantity)
        self.assertTrue(roll <= (dice.quantity * dice.sides))
    def exitDice(self, ctx):
        self._logger.debug("Exiting dice %s", ctx.getText())
        self._logger.debug("Quantity %s, sides %s",
                           ctx.DIGIT()[0],
                           ctx.DIGIT()[1])
        digits = iter(ctx.DIGIT())
        if (len(ctx.DIGIT()) > 1):
            # Contains the quantity of dice
            quantity = int(next(digits).getText())
        else:
            # No quantity of dice defined
            # Defaults to 1
            quantity = 1

        sides = int(next(digits).getText())

        dice = RollableDice(quantity, sides)
        self._nodes.append(dice)