-
Notifications
You must be signed in to change notification settings - Fork 24
/
tatqa_utils_test.py
45 lines (34 loc) · 1.19 KB
/
tatqa_utils_test.py
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
import pytest
from tatqa_utils import *
def test_extract_first_num_from_text():
text = '2.3 million'
assert extract_one_num_from_str(text) == 2.3
text = '-2.3 million'
assert extract_one_num_from_str(text) == -2.3
text = '205 million'
assert extract_one_num_from_str(text) == 205
text = '-1,210 million'
assert extract_one_num_from_str(text) == -1210
def test_to_num():
text = '2.3 million'
assert to_number(text) == 2300000
text = '-2.3 thousand'
assert to_number(text) == -2300
text = '205 billion'
assert to_number(text) == 205000000000
text = '-1,210 million'
assert to_number(text) == -1210000000
def test_ws_tokenize():
text = '2.3 million'
assert ws_tokenize(text) == ['2.3', 'million']
text = '2.3 \nmillion'
assert ws_tokenize(text) == ['2.3', 'million']
text = '2.3\n\tmillion'
assert ws_tokenize(text) == ['2.3', 'million']
def test_normalize_answer():
assert normalize_answer('-134.12') == '-134.12'
assert normalize_answer('134.12') == '134.12'
assert normalize_answer('(134.12)') == '-134.12'
assert normalize_answer('18.3%') == '0.183'
def test_is_num():
assert is_number('$124')