-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
56 lines (51 loc) · 1.97 KB
/
tests.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
46
47
48
49
50
51
52
53
54
55
56
import csv
from translate import translate
def test(race):
failures = []
total = 0
with open(f'test_data/{race}_words.csv', 'r', newline='') as f:
data = csv.reader(f)
for row in data:
word = row[1]
word_capitalized = word.capitalize()
# Compare the lower case words.
expected_trans_lower = row[2]
trans_lower = translate(word, race)
if trans_lower != expected_trans_lower:
failures.append(f'{word}: {trans_lower} - '
f'({expected_trans_lower})')
total += 1
# Compare the capitalized words.
if len(row) >= 4:
expected_trans_capitalized = row[3]
trans_capitalized = translate(word_capitalized, race)
if trans_capitalized != expected_trans_capitalized:
failures.append(f'{word_capitalized}: '
f'{trans_capitalized} - '
f'({expected_trans_capitalized})')
total += 1
if len(row) == 5:
word_uppercase = word.upper()
expected_trans_uppercase = row[4]
trans_uppercase = translate(word_uppercase, race)
if trans_uppercase != expected_trans_uppercase:
failures.append(f'{word_uppercase}: {trans_uppercase} - '
f'({expected_trans_uppercase})')
total += 1
print(f'Results: {len(failures)}/{total}')
with open(f'test_results_{race}.txt', 'w') as f:
f.write('\n'.join(failures))
return len(failures), total
if __name__ == "__main__":
failures = 0
total = 0
f, t = test('explorers')
failures += f
total += t
f, t = test('warriors')
failures += f
total += t
f, t = test('traders')
failures += f
total += t
print(f'{100 * (total - failures) / total}% conversion rate success!')