Skip to content

Commit d7587b3

Browse files
committed
test: add English ITN unit tests (43 cases)
1 parent c528838 commit d7587b3

8 files changed

Lines changed: 79 additions & 0 deletions

File tree

itn/english/__init__.py

Whitespace-only changes.

itn/english/rules/__init__.py

Whitespace-only changes.

itn/english/test/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
twenty three => 23
2+
one hundred => 100
3+
one hundred and one => 101
4+
two hundred and fifty four => 254
5+
one thousand => 1000
6+
one thousand two hundred thirty four => 1234
7+
eleven hundred => 1100
8+
twenty one hundred => 2100
9+
twenty one hundred and eleven => 2111
10+
ten thousand => 10000
11+
one hundred thousand => 100000
12+
one million => 1000000
13+
one billion => 1000000000
14+
one trillion => 1000000000000
15+
one thousand and one => 1001
16+
one million one => 1000001
17+
one billion five hundred ninety three million seventy two thousand nine hundred sixty one => 1593072961
18+
zero => 0
19+
five => 5
20+
thirty => 30
21+
minus forty two => -42
22+
negative five => -5
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
twelve point five => 12.5
2+
three point one four => 3.14
3+
minus three point one four => -3.14
4+
point o five => .05
5+
point five => .5
6+
one point zero => 1.0
7+
zero point five => 0.5
8+
twenty three point four five six => 23.456
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
first => 1st
2+
second => 2nd
3+
third => 3rd
4+
fourth => 4th
5+
fifth => 5th
6+
eleventh => 11th
7+
twelfth => 12th
8+
thirteenth => 13th
9+
twenty first => 21st
10+
thirty second => 32nd
11+
forty third => 43rd
12+
one hundredth => 100th
13+
one hundred and first => 101st
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2026 Zhendong Peng (pzd17@tsinghua.org.cn)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from itertools import chain
16+
17+
import pytest
18+
19+
from itn.english.rules.inverse_normalizer import InverseNormalizer
20+
from itn.english.test.utils import parse_test_case
21+
22+
23+
class TestNormalizer:
24+
25+
normalizer = InverseNormalizer(overwrite_cache=True)
26+
27+
normalizer_cases = chain(
28+
parse_test_case("data/en_cardinal.txt"),
29+
parse_test_case("data/en_ordinal.txt"),
30+
parse_test_case("data/en_decimal.txt"),
31+
)
32+
33+
@pytest.mark.parametrize("spoken, written", normalizer_cases)
34+
def test_normalizer(self, spoken, written):
35+
assert self.normalizer.normalize(spoken) == written

itn/english/test/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../tn/chinese/test/utils.py

0 commit comments

Comments
 (0)