예제 #1
0
    def setUp(self):
        self._mock_syntax = [
            mock.create_autospec(i_dice_expression.IDiceExpression) for _ in range(2)
        ]
        self._mock_syntax[0].roll.return_value = 10
        self._mock_syntax[0].max.return_value = 8
        self._mock_syntax[0].min.return_value = 6
        self._mock_syntax[0].__str__.return_value = "7d7"
        self._mock_syntax[0].estimated_cost.return_value = 9
        self._mock_syntax[
            0
        ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
            {-2: 1, 4: 1}
        )

        self._mock_syntax[1].roll.return_value = 4
        self._mock_syntax[1].max.return_value = 6
        self._mock_syntax[1].min.return_value = 8
        self._mock_syntax[1].__str__.return_value = "2d2"
        self._mock_syntax[1].estimated_cost.return_value = 7
        self._mock_syntax[
            1
        ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
            {8: 1, -3: 2}
        )

        self._test_minmax = minmax_expression.MinMaxExpression(
            "MAX", self._mock_syntax[0], self._mock_syntax[1]
        )
        self._mock_parser_gen = mock.create_autospec(rply.ParserGenerator)
예제 #2
0
 def test_min_get_probability_distribution_third_example(self):
     self._test_minmax = minmax_expression.MinMaxExpression(
         "MIN", self._mock_syntax[0], self._mock_syntax[1]
     )
     self._mock_syntax[
         0
     ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
         {-3: 1, -2: 1, -1: 1, 0: 1, 5: 1, 6: 1}
     )
     self._mock_syntax[
         1
     ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
         {0: 1}
     )
     self.assertEqual(
         {-3: 1, -2: 1, -1: 1, 0: 3},
         self._test_minmax.get_probability_distribution().get_result_map(),
     )
예제 #3
0
 def test_min_get_probability_distribution(self):
     self._test_minmax = minmax_expression.MinMaxExpression(
         "MIN", self._mock_syntax[0], self._mock_syntax[1]
     )
     self._mock_syntax[
         0
     ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
         {10: 1, -12: 2, 0: 1}
     )
     self._mock_syntax[
         1
     ].get_probability_distribution.return_value = probability_distribution.ProbabilityDistribution(
         {2: 1, 3: 2}
     )
     self.assertEqual(
         {-12: 6, 0: 3, 2: 1, 3: 2},
         self._test_minmax.get_probability_distribution().get_result_map(),
     )
예제 #4
0
 def test_min_str(self):
     self._test_minmax = minmax_expression.MinMaxExpression(
         "MIN", self._mock_syntax[0], self._mock_syntax[1]
     )
     self.assertEqual("MIN(7d7, 2d2)", str(self._test_minmax))
예제 #5
0
 def test_min_min(self):
     self._test_minmax = minmax_expression.MinMaxExpression(
         "MIN", self._mock_syntax[0], self._mock_syntax[1]
     )
     self.assertEqual(6, self._test_minmax.min())
예제 #6
0
 def test_min_roll(self):
     self._test_minmax = minmax_expression.MinMaxExpression(
         "MIN", self._mock_syntax[0], self._mock_syntax[1]
     )
     for _ in range(100):
         self.assertEqual(4, self._test_minmax.roll())