diff --git a/src/mcp_server_calculator/calculator.py b/src/mcp_server_calculator/calculator.py index 19ced8a..be97f8e 100644 --- a/src/mcp_server_calculator/calculator.py +++ b/src/mcp_server_calculator/calculator.py @@ -26,6 +26,7 @@ def eval_expr(node): return -eval_expr(node.operand) raise ValueError(f"Unsupported operation: {ast.dump(node)}") + expression = expression.replace('^', '**').replace('×', '*').replace('÷', '/') parsed_expr = ast.parse(expression, mode='eval') result = eval_expr(parsed_expr.body) return str(result) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 17796ba..08dcb2b 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -10,9 +10,11 @@ def test_subtraction(self): def test_multiplication(self): self.assertEqual(evaluate("2 * 3"), "6") + self.assertEqual(evaluate("2 × 3"), "6") def test_division(self): self.assertEqual(evaluate("8 / 2"), "4.0") + self.assertEqual(evaluate("8 ÷ 2"), "4.0") def test_floor_division(self): self.assertEqual(evaluate("7 // 2"), "3") @@ -22,6 +24,7 @@ def test_modulus(self): def test_power(self): self.assertEqual(evaluate("2 ** 3"), "8") + self.assertEqual(evaluate("2 ^ 3"), "8") def test_unary_minus(self): self.assertEqual(evaluate("-5"), "-5")