Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
·
42e76ea
1
Parent(s):
426598f
test: add test cases for edit_distance_python()
Browse files
tests/test_phonem_converter_score.py
CHANGED
@@ -2,10 +2,14 @@ import unittest
|
|
2 |
|
3 |
import epitran
|
4 |
|
5 |
-
from aip_trainer import pronunciationTrainer
|
6 |
from aip_trainer.models import RuleBasedModels
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
9 |
class TestPhonemConverter(unittest.TestCase):
|
10 |
|
11 |
def test_english_ok(self):
|
@@ -26,8 +30,6 @@ trainer_SST_lambda = {'de': pronunciationTrainer.getTrainer("de")}
|
|
26 |
class TestScore(unittest.TestCase):
|
27 |
|
28 |
def test_exact_transcription(self):
|
29 |
-
words_real = 'Ich habe sehr viel glück, am leben und gesund zu sein'
|
30 |
-
|
31 |
real_and_transcribed_words, _, _ = trainer_SST_lambda['de'].matchSampleAndRecordedWords(
|
32 |
words_real, words_real)
|
33 |
|
@@ -37,8 +39,6 @@ class TestScore(unittest.TestCase):
|
|
37 |
self.assertEqual(int(pronunciation_accuracy), 100)
|
38 |
|
39 |
def test_incorrect_transcription(self):
|
40 |
-
words_real = 'Ich habe sehr viel glück, am leben und gesund zu sein'
|
41 |
-
words_transcribed = 'Ic hab zeh viel guck am und gesund tu sein'
|
42 |
|
43 |
real_and_transcribed_words, _, _ = trainer_SST_lambda['de'].matchSampleAndRecordedWords(
|
44 |
words_real, words_transcribed)
|
@@ -48,6 +48,64 @@ class TestScore(unittest.TestCase):
|
|
48 |
|
49 |
self.assertEqual(int(pronunciation_accuracy), 71)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
if __name__ == '__main__':
|
53 |
unittest.main()
|
|
|
2 |
|
3 |
import epitran
|
4 |
|
5 |
+
from aip_trainer import pronunciationTrainer, WordMetrics
|
6 |
from aip_trainer.models import RuleBasedModels
|
7 |
|
8 |
|
9 |
+
words_real = 'Ich habe sehr viel glück, am leben und gesund zu sein'
|
10 |
+
words_transcribed = 'Ic hab zeh viel guck am und gesund tu sein'
|
11 |
+
|
12 |
+
|
13 |
class TestPhonemConverter(unittest.TestCase):
|
14 |
|
15 |
def test_english_ok(self):
|
|
|
30 |
class TestScore(unittest.TestCase):
|
31 |
|
32 |
def test_exact_transcription(self):
|
|
|
|
|
33 |
real_and_transcribed_words, _, _ = trainer_SST_lambda['de'].matchSampleAndRecordedWords(
|
34 |
words_real, words_real)
|
35 |
|
|
|
39 |
self.assertEqual(int(pronunciation_accuracy), 100)
|
40 |
|
41 |
def test_incorrect_transcription(self):
|
|
|
|
|
42 |
|
43 |
real_and_transcribed_words, _, _ = trainer_SST_lambda['de'].matchSampleAndRecordedWords(
|
44 |
words_real, words_transcribed)
|
|
|
48 |
|
49 |
self.assertEqual(int(pronunciation_accuracy), 71)
|
50 |
|
51 |
+
def test_edit_distance_python(self):
|
52 |
+
output = WordMetrics.edit_distance_python(words_real, words_transcribed)
|
53 |
+
self.assertEqual(output, int(14))
|
54 |
+
|
55 |
+
def test_edit_distance_python_same(self):
|
56 |
+
output = WordMetrics.edit_distance_python(words_real, words_real)
|
57 |
+
self.assertEqual(output, int(0))
|
58 |
+
|
59 |
+
def test_edit_distance_python_empty(self):
|
60 |
+
output = WordMetrics.edit_distance_python("", "")
|
61 |
+
self.assertEqual(output, int(0))
|
62 |
+
output = WordMetrics.edit_distance_python(words_real, "")
|
63 |
+
self.assertEqual(output, int(53))
|
64 |
+
output = WordMetrics.edit_distance_python("", words_real)
|
65 |
+
self.assertEqual(output, int(53))
|
66 |
+
|
67 |
+
def test_edit_distance_python_not_printable_characters(self):
|
68 |
+
output = WordMetrics.edit_distance_python("Ich bin Alex\t a\0b! Hallo.", "Ich bi\tn Tom a\nc... Hallo")
|
69 |
+
self.assertEqual(output, int(12))
|
70 |
+
|
71 |
+
def test_edit_distance_python_survived(self):
|
72 |
+
# These tests are added based on the mutation test results to ensure the function is robust
|
73 |
+
|
74 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Add_Mul
|
75 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr")
|
76 |
+
self.assertEqual(output, int(5))
|
77 |
+
|
78 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Add_Div
|
79 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel")
|
80 |
+
self.assertEqual(output, int(10))
|
81 |
+
|
82 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Add_FloorDiv
|
83 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück")
|
84 |
+
self.assertEqual(output, int(16))
|
85 |
+
|
86 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Add_Pow
|
87 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am")
|
88 |
+
self.assertEqual(output, int(20))
|
89 |
+
|
90 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Sub_Mod
|
91 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am leben")
|
92 |
+
self.assertEqual(output, int(26))
|
93 |
+
|
94 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Sub_RShift
|
95 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am leben und")
|
96 |
+
self.assertEqual(output, int(30))
|
97 |
+
|
98 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Sub_LShift
|
99 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am leben und gesund")
|
100 |
+
self.assertEqual(output, int(37))
|
101 |
+
|
102 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Sub_BitAnd
|
103 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am leben und gesund zu")
|
104 |
+
self.assertEqual(output, int(40))
|
105 |
+
|
106 |
+
# Test case where mutation survived for ReplaceBinaryOperator_Sub_BitXor
|
107 |
+
output = WordMetrics.edit_distance_python("Ich habe", "Ich habe sehr viel glück, am leben und gesund zu sein")
|
108 |
+
self.assertEqual(output, int(45))
|
109 |
|
110 |
if __name__ == '__main__':
|
111 |
unittest.main()
|