nidhal baccouri
commited on
Commit
·
fd6b374
1
Parent(s):
a05c704
updated tests
Browse files- tests/test_google_trans.py +1 -25
tests/test_google_trans.py
CHANGED
@@ -129,43 +129,19 @@ def google_translator():
|
|
129 |
"""
|
130 |
return GoogleTranslator(target='en')
|
131 |
|
132 |
-
|
133 |
-
def case_sensitivity_checks():
|
134 |
-
test_lang = 'Czech'
|
135 |
-
test_text = 'Hi, the sky is dark while the moon is white. Hurrah!! Denver is a city name in Colorado.'
|
136 |
-
translated_text = 'Ahoj, obloha je tmavá, zatímco měsíc je bílý. Hurá!! Denver je název města v Coloradu.'
|
137 |
-
test_cases = []
|
138 |
-
n = len(test_lang)
|
139 |
-
mx = 1 << n
|
140 |
-
test = test_lang.lower()
|
141 |
-
for i in range(mx):
|
142 |
-
combination = [k for k in test_lang]
|
143 |
-
for j in range(n):
|
144 |
-
if (((i >> j) & 1) == 1):
|
145 |
-
combination[j] = test_lang[j].upper()
|
146 |
-
temp = ""
|
147 |
-
for i in combination:
|
148 |
-
temp += i
|
149 |
-
test_cases.append(temp)
|
150 |
-
random_cases = 5
|
151 |
-
random_test_cases = random.sample(test_cases, random_cases) # randomly choosing any five cases since list is in order of 2^n containing all cases
|
152 |
-
for case in random_test_cases:
|
153 |
-
assert GoogleTranslator(source='en', target=case).translate(test_text) == translated_text
|
154 |
-
|
155 |
def multiple_names_lang_checks():
|
156 |
assert GoogleTranslator(source='en', target='burMeSe').translate("Hello") == 'မင်္ဂလာပါ'
|
157 |
assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
|
158 |
assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'
|
159 |
|
160 |
def test_random_tranlations_cases_multiple_names():
|
161 |
-
random_sample_size =
|
162 |
d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
|
163 |
random_lang_names = random.sample(d.keys(), random_sample_size)
|
164 |
random_subset_dict = {k: TRANSLATED_RESULTS[k] for k in random_lang_names}
|
165 |
for lang, translation in random_subset_dict.items():
|
166 |
assert GoogleTranslator(source='en', target=lang).translate(test_text_standard) == translation
|
167 |
|
168 |
-
case_sensitivity_checks()
|
169 |
multiple_names_lang_checks()
|
170 |
|
171 |
def test_content(google_translator):
|
|
|
129 |
"""
|
130 |
return GoogleTranslator(target='en')
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
def multiple_names_lang_checks():
|
133 |
assert GoogleTranslator(source='en', target='burMeSe').translate("Hello") == 'မင်္ဂလာပါ'
|
134 |
assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
|
135 |
assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'
|
136 |
|
137 |
def test_random_tranlations_cases_multiple_names():
|
138 |
+
random_sample_size = 2
|
139 |
d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
|
140 |
random_lang_names = random.sample(d.keys(), random_sample_size)
|
141 |
random_subset_dict = {k: TRANSLATED_RESULTS[k] for k in random_lang_names}
|
142 |
for lang, translation in random_subset_dict.items():
|
143 |
assert GoogleTranslator(source='en', target=lang).translate(test_text_standard) == translation
|
144 |
|
|
|
145 |
multiple_names_lang_checks()
|
146 |
|
147 |
def test_content(google_translator):
|