数据驱动,关键字驱动,混合驱动简单模型
Posted king-tong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据驱动,关键字驱动,混合驱动简单模型相关的知识,希望对你有一定的参考价值。
数据驱动:
data=[(1,1,2),(2,2,4),(3,3,9)]
def execute(t):
result=0
for i in t[:-1]:
result+=i
return result
if __name__=="__main__":
for i in data:
actual_result=execute(i)
expected_result=i[-1]
try:
assert actual_result== expected_result
print("pass--->actual_result=%s expected_result=%s"%(actual_result,expected_result))
except AssertionError:
print("fail--->actual_result=%s expected_result=%s"%(actual_result,expected_result))
关键字驱动:
def add(*args):
result=0
for i in args:
result+=i
return result
def sub(*args):
result=args[0]
for i in args[1:]:
result-=i
return result
def handleTestData(filepath):
with open(filepath) as fp:
content=fp.readlines()
data=[ i.split("||") for i in content ]
return data
if __name__=="__main__":
filepath="d:\pydelete\0628\a.txt"
data=handleTestData(filepath)
for i in data:
func=i[0]
testdata=[ int(j) for j in i[1:-1]]
expected_result=i[-1]
try:
if func=="add":
actual_result=add(*testdata)
assert actual_result==int(expected_result)
print("pass--->func is %s actual_result=%s expected_result=%s" %(func,actual_result,expected_result))
elif func=="sub":
actual_result=sub(*testdata)
assert actual_result==int(expected_result)
print("pass--->func is %s actual_result=%s expected_result=%s" %(func,actual_result,expected_result))
except AssertionError:
print("fail--->func is %s actual_result=%s expected_result=%s"%(func,actual_result,expected_result))
以上是关于数据驱动,关键字驱动,混合驱动简单模型的主要内容,如果未能解决你的问题,请参考以下文章