-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcase.py
41 lines (39 loc) · 1.13 KB
/
testcase.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
import random
import json
fread = open('data/corpus.txt','r')
sentence = fread.read()
lines = sentence.split('\n')
# print(lines)
fread.close()
confmat=open('data/conf_matrix.json')
replace=json.load(confmat)
fwrite = open('data/input.txt','w')
inputtotal = ''
# print(replace['a'][0])
for line in lines:
if(line=='\n' or line==' ' or line==''):
print('ALL TEST CASES OVER')
break
else:
l = len(line)
change = random.randint(4,10)
indices = []
inputtext = ''
for c in range(change):
ind = random.randint(0,l-1)
indices.append(ind)
indices.sort()
for i in range(len(line)):
if(len(indices)>0):
if(i==indices[0] and line[i]!=' '):
conf_arr=replace[line[i]]
r = random.randint(0,len(conf_arr)-1)
inputtext+=(replace[line[i]][r])
indices.pop(0)
else:
inputtext+=line[i]
else:
inputtext+=line[i]
inputtotal+=(inputtext+'\n')
fwrite.write(inputtotal)
fwrite.close()