def test_uses_starting_state(self): test_interpreter_one = PythonDiceInterpreter() probability_distribution = test_interpreter_one.get_probability_distributions(["d12"])["stdout"] mock_state = create_autospec(IProbabilityDistributionState) mock_state.get_var.return_value = probability_distribution mock_state.get_constant_dict.return_value = {"stored_value": 12} interpreter = PythonDiceInterpreter(starting_state=mock_state) program = ["d12 + stored_value"] self.assertEqual(24, interpreter.max(program)["stdout"])
def test_uses_given_parser(self): mock_expression = create_autospec(IDiceExpression) mock_expression.max.return_value = 12 mock_parser = create_autospec(IPythonDiceParser) mock_parser.parse.return_value = (mock_expression, None) interpreter = PythonDiceInterpreter(mock_parser) program = ["d12"] self.assertEqual(12, interpreter.max(program)["stdout"]) mock_expression.max.assert_called_once() mock_parser.parse.assert_called_once_with("d12", ANY)
def test_max_single_line(self): interpreter = PythonDiceInterpreter() program = ["d20 + 8"] self.assertEqual(28, interpreter.max(program)["stdout"])