-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runner.py
More file actions
28 lines (28 loc) · 986 Bytes
/
test_runner.py
File metadata and controls
28 lines (28 loc) · 986 Bytes
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
import json, time, unicodedata
from caesar_cli import transform
def normalize_orig(s):
out=''
for ch in s:
nf = unicodedata.normalize('NFD', ch)
if len(nf)>=2 and nf[0].lower()=='n' and '\u0303' in nf:
out += 'Ñ' if nf[0].isupper() else 'ñ'
else:
out += ''.join(c for c in nf if unicodedata.category(c)!='Mn')
return out
def run():
with open('test.json','r',encoding='utf-8') as f:
data = json.load(f)
tests = data.get('tests', [])
start = time.time()
failures = 0
ops = 0
for rep in range(100):
for t in tests:
ops += 1
enc = transform(t['input'], t['shift'], t.get('lang','es'))
dec = transform(enc, -t['shift'], t.get('lang','es'))
if dec != normalize_orig(t['input']):
failures += 1
elapsed = time.time() - start
print(f'Ran {ops} ops in {elapsed:.3f}s. Failures: {failures}')
if __name__=='__main__': run()