Repository navigation
Expand file tree
/
Copy pathtest_normalizer.py
More file actions
58 lines (52 loc) · 2.05 KB
/
Copy pathtest_normalizer.py
File metadata and controls
58 lines (52 loc) · 2.05 KB
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
import unittest
from text_normalizer import normalize_date, normalize_amount_numeric, normalize_amount_in_words
class TestTextNormalizer(unittest.TestCase):
def test_normalize_date(self):
cases = [
("20-sep-2025", "20-09-2025"),
("20 september 2025", "20-09-2025"),
("20-9-2025", "20-09-2025"),
("2092025", "20-09-2025"),
("20092025", "20-09-2025"),
("1.1.2023", "01-01-2023"),
("2092025", "20-09-2025"), # 7 digit check
# ("2209202", "22-09-2025") # This is ambiguous/broken input, verifying behavior
]
for inp, expected in cases:
res = normalize_date(inp)
if res != expected:
print(f"FAIL [Date]: '{inp}' -> '{res}', expected '{expected}'")
self.assertEqual(res, expected)
def test_normalize_amount_numeric(self):
cases = [
("2300", 2300.0),
("2s00", 2500.0),
("23oo", 2300.0),
("z3.50", 23.50),
("S000", 5000.0),
("1,00,000", 100000.0),
("yo0o", 4000.0), # 'y' -> 4
]
for inp, expected in cases:
res = normalize_amount_numeric(inp)
self.assertEqual(res, expected)
def test_normalize_amount_in_words(self):
cases = [
("two thousand three hundred only", 2300),
("two thousand three hundred", 2300),
("Five Thousand only", 5000),
("one lack", 100000),
("one lakh", 100000),
("one crore", 10000000),
("five million", 5000000),
("twnty fve thsand", 25000),
("one lack fifty thosand", 150000),
("Fouvthousend", 4000) # Joined words with spelling error
]
for inp, expected in cases:
res = normalize_amount_in_words(inp)
if res != expected:
print(f"FAIL [Words]: '{inp}' -> {res}, expected {expected}")
self.assertEqual(res, expected)
if __name__ == '__main__':
unittest.main()