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)