"""The benchmark's comparison, which is built on the one figure reader
rather than a reading of its own."""

from quber.playground.benchmark.run_shapes import gold_in_prose, looks_like_prose, values_agree


def test_values_agree_exact_and_numeric():
    both = values_agree("6.7 %", "6.7 %")
    assert both == {"exact": True, "numeric": True}
    # Same figure printed differently: numeric agreement without exact.
    spaced = values_agree("$(10,550)", "$ (10,550)")
    assert spaced["numeric"] is True
    assert values_agree(None, "6.7 %") == {"exact": False, "numeric": False}
    assert values_agree("6.8%", "6.7%")["numeric"] is False


def test_looks_like_prose():
    assert looks_like_prose("The revenue for the quarter was $1.2 million overall")
    assert not looks_like_prose("$1.2 million")
    assert not looks_like_prose(None)


def test_gold_found_in_prose_as_printed_and_as_number():
    assert gold_in_prose("Distributions were $(10,550) thousand in Q1.", "$ (10,550)")
    assert gold_in_prose("The coupon was 6.7% for securitized loans.", "6.7 %")
    assert not gold_in_prose("No figures here.", "6.7 %")


def test_sentence_full_stop_does_not_join_a_token():
    # "1,234." at the end of a sentence: the decimal part must be a real
    # decimal, or the trailing full stop makes an unparseable token and the
    # match silently fails.
    assert gold_in_prose("The total was 1,234.", "1,234")
