import pytest from answer_formatter import apply_requested_format, format_answer def test_removes_only_presentation_noise(): assert format_answer(' Final answer: "New York" ') == "New York" assert format_answer("McDONALD") == "McDONALD" def test_rejects_empty_answer(): with pytest.raises(ValueError): format_answer(" ") def test_removes_explanations_without_changing_punctuation(): assert ( format_answer("FINAL ANSWER: USA, FRA\nExplanation: looked it up") == "USA, FRA" ) assert format_answer("Answer: $12.50 because the sum is exact") == "$12.50" def test_collapses_accidental_newlines_but_preserves_exact_characters(): assert format_answer("USA,\nFRA") == "USA, FRA" assert format_answer("Qh7+\n") == "Qh7+" def test_applies_only_explicit_question_formatting(): assert apply_requested_format( "Express in USD with two decimal places", "34675.5" ) == ("$34,675.50") assert ( apply_requested_format( "comma-delimited list in ascending order", "245, 132, 197" ) == "132, 197, 245" ) assert ( apply_requested_format("alphabetize the comma separated list", "pear, apple") == "apple, pear" )