File size: 1,277 Bytes
c641d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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"
    )