alu-chatbot / enhanced_capabilities /test_math_solver.py
Donne120
Claude Opus 5
Delete quarantined fabricated knowledge; make the math test a real test
c1eb5fc
Raw History Blame Contribute Delete
1.53 kB
"""Tests for the math solver used by capability_router.
Previously this file printed results and asserted nothing, so it passed no
matter what the solver returned — and its bare `from math_solver import`
only resolved when pytest ran from inside this directory, which broke
collection for the whole suite.
"""
from .math_solver import extract_math_expression, is_math_question, solve_math_problem
def test_recognises_math_questions():
assert is_math_question("2x+4=0 find x")
assert is_math_question("solve for x: 3x - 6 = 0")
def test_ignores_non_math_questions():
assert not is_math_question("When does the next term start?")
assert not is_math_question("Who is my academic adviser?")
def test_extracts_the_equation_from_surrounding_words():
# The equation should survive being embedded in a sentence, with or
# without a space before the trailing instruction.
assert "2x+4=0" in extract_math_expression("2x+4=0 find x").replace(" ", "")
assert "2x+4=0" in extract_math_expression("2x+4=0find x").replace(" ", "")
assert "3x-6=0" in extract_math_expression("solve for x: 3x - 6 = 0").replace(" ", "")
def test_solves_a_linear_equation():
answer, steps = solve_math_problem("2x+4=0 find x")
# 2x + 4 = 0 -> x = -2
assert "-2" in answer
assert isinstance(steps, list) and steps
def test_returns_working_steps():
_, steps = solve_math_problem("solve for x: 3x - 6 = 0")
assert isinstance(steps, list)
assert all(isinstance(s, str) for s in steps)