File size: 1,398 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
from backend.entity_resolver import resolve_entity, normalize_org_name, format_money


EXISTING = ["Apple", "HDFC Bank", "3M"]


def test_alias_table_resolves_ticker():
    assert resolve_entity("AAPL", "ORG", EXISTING) == "ORG_Apple"


def test_legal_suffix_stripped():
    assert resolve_entity("Apple Inc.", "ORG", EXISTING) == "ORG_Apple"
    assert resolve_entity("HDFC Bank Limited", "ORG", EXISTING) == "ORG_HDFC Bank"


def test_short_name_not_mangled():
    assert resolve_entity("3M Company", "ORG", EXISTING) == "ORG_3M"


def test_non_org_labels_pass_through():
    assert resolve_entity("$394.3 billion", "MONEY", EXISTING).startswith("MONEY_")


def test_normalize_strips_trailing_suffixes_only():
    assert normalize_org_name("Reliance Industries Limited") == "reliance"
    # 'Industries' is a LEGAL_SUFFIXES entry, but only trailing words drop
    assert normalize_org_name("Industries First Corp") == "industries first"


def test_format_money_inr_crore():
    # 60,812 crore in absolute rupees
    assert format_money(60_812 * 10_000_000, "INR") == "₹60,812.0 Cr"


def test_format_money_inr_lakh_crore():
    assert "Lakh Cr" in format_money(2.7e13, "INR")


def test_format_money_usd():
    assert format_money(394_300_000_000, "USD") == "$394.3B"
    assert format_money(45_000_000, "USD") == "$45.0M"


def test_format_money_none():
    assert format_money(None) == "N/A"