-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
33 lines (26 loc) · 1.41 KB
/
test_utils.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
import unittest
import utils # utilsモジュールをインポート
class TestUtils(unittest.TestCase):
def test_calculate_CER(self):
# "hello" と "hello" のCERが0であることを確認
self.assertEqual(utils.calculate_CER("hello", "hello"), 0)
# 削除1回
self.assertEqual(utils.calculate_CER("hello", "hell"), 1/5)
# 挿入1回
self.assertEqual(utils.calculate_CER("hello", "hellao"), 1/5)
# 置換1回
self.assertEqual(utils.calculate_CER("hello", "hallo"), 1/5)
def test_calculate_MinCER(self):
# "hello" と ["hello"] のCERが0であることを確認
self.assertEqual(utils.calculate_MinCER(["hello", "hallo"], "hello"), 0)
# "hello" と ["hallo", "hollo"] のCERが1/5であることを確認
self.assertEqual(utils.calculate_MinCER(["hallo", "hollo"], "hello"), 1/5)
def test_calculate_ACCat1(self):
# "hello" と ["hello"] のaccuracyが1であることを確認
self.assertEqual(utils.calculate_accuracy_at1(["hello"], "hello"), 1)
# "hello" と ["hello", "world"] のaccuracyが1であることを確認
self.assertEqual(utils.calculate_accuracy_at1(["hello", "world"], "hello"), 1)
# "hello" と ["world"] のaccuracyが0であることを確認
self.assertEqual(utils.calculate_accuracy_at1(["world"], "hello"), 0)
if __name__ == "__main__":
unittest.main()