File size: 2,339 Bytes
d4f8959 | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from backend.verifier import verify_answer, extract_numbers
SOURCE = (
"The Consolidated total revenue from operations for the year was "
"₹ 9,64,693 crore, compared to ₹ 9,01,064 crore in the previous year. "
"Profit after tax was ₹ 60,812 crore. Attrition was 12.5%."
)
METRICS = {
"revenue": {"value": 9_64_693 * 10_000_000, "confidence": "high"},
"profit_after_tax": {"value": 60_812 * 10_000_000, "confidence": "high"},
}
def test_faithful_answer_verifies():
answer = "Revenue was ₹9,64,693 crore and PAT was ₹60,812 crore. Attrition stood at 12.5%."
result = verify_answer(answer, SOURCE, METRICS)
assert result["all_verified"] is True
assert result["unverified"] == []
def test_invented_numbers_flagged():
answer = "Revenue was ₹9,64,693 crore. The company spent ₹5,000 crore on R&D and grew 45%."
result = verify_answer(answer, SOURCE, METRICS)
assert result["all_verified"] is False
flagged = {u["value"] for u in result["unverified"]}
assert 5000.0 in flagged
assert 45.0 in flagged
def test_unit_conversion_matches_across_formats():
# $394.3B in the answer vs "394,328 million" in the source
source = "Total net sales were $394,328 million in fiscal 2022."
answer = "Apple's revenue was $394.3 billion."
result = verify_answer(answer, source, None)
assert result["all_verified"] is True
def test_format_money_output_is_parseable():
# the exact strings format_money() produces must round-trip
source = "profit after tax: ₹60,812.0 Cr"
answer = "PAT was ₹60,812.0 Cr."
assert verify_answer(answer, source, None)["all_verified"] is True
def test_years_and_small_numbers_ignored():
answer = "In 2024, the top 3 segments performed well."
result = verify_answer(answer, "irrelevant source", None)
assert result["checked"] == 0
assert result["all_verified"] is True
def test_no_numbers_is_trivially_verified():
result = verify_answer("Not available in filing.", SOURCE, METRICS)
assert result["all_verified"] is True
assert result["checked"] == 0
def test_extract_numbers_shapes():
nums = extract_numbers("Revenue was ₹1,22,670.1 crore, margin 24.6%.")
raws = [n["raw"] for n in nums]
assert any("crore" in r for r in raws)
assert any("%" in r for r in raws)
|