-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCase.py
66 lines (65 loc) · 2.58 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QFileDialog
import re
import itertools
class TestCase(object):
#生成决策表
def create(self,condition):
each=re.split('\|\||\&\&|\(|\)',condition)
while '' in each:
each.remove('')
result=[]
var=[]
correct=[]
error=[]
rco=condition
rer=condition
for i in range(len(each)):
if '==' in each[i]:
var.append(re.split('==',each[i])[0])
correct.append(int(re.split('==',each[i])[1]))
error.append(int(re.split('==',each[i])[1])+1)
elif '!=' in each[i]:
var.append(re.split('!=',each[i])[0])
correct.append(int(re.split('!=',each[i])[1])+1)
error.append(int(re.split('!=',each[i])[1]))
elif '!' in each[i]:
var.append(each[i].strip('!'))
correct.append(0)
error.append(1)
rer=re.sub('!',' not ',rer)
rco=re.sub('!',' not ',rco)
elif '>=' in each[i]:
var.append(re.split('>=',each[i])[0])
correct.append(int(re.split('>=',each[i])[1]))
error.append(int(re.split('>=',each[i])[1])-1)
elif '<=' in each[i]:
var.append(re.split('<=',each[i])[0])
correct.append(int(re.split('<=',each[i])[1]))
error.append(int(re.split('<=',each[i])[1])+1)
elif '>' in each[i]:
var.append(re.split('>',each[i])[0])
correct.append(int(re.split('>',each[i])[1])+1)
error.append(int(re.split('>',each[i])[1]))
elif '<' in each[i]:
var.append(re.split('<',each[i])[0])
correct.append(int(re.split('<',each[i])[1])-1)
error.append(int(re.split('<',each[i])[1]))
else:
var.append(each[i])
correct.append(1)
error.append(0)
rco=re.sub(r'\b{0}\b'.format(var[i]),str(correct[i]),rco)
rer=re.sub(r'\b{0}\b'.format(var[i]),str(error[i]),rer)
var.append(condition)
rco=re.sub('\|\|',' or ',rco)
rco=re.sub('\&\&',' and ',rco)
rer=re.sub('\|\|',' or ',rer)
rer=re.sub('\&\&',' and ',rer)
correct.append(eval(rco))
error.append(eval(rer))
result.append(var)
result.append(correct)
result.append(error)
return result