# bin_check.py
dict_test = {1: 'fail', 2: 'fail', 3: 'fail', 4: 'fail', 5: 'fail', 6: 'fail', 7: 'pass', 8: 'pass', 9: 'pass',
10: 'pass'}
def bin_check(dict_test: dict, mid):
if int(dict_test[mid]) > 10:
return "pass"
else:
return "fail"
print(dict_test.get[mid])
# 从 a.txt 读取参数,转成字典的格式
# with open('a.txt', 'r') as file:
# param_list = [line.strip() for line in file]
#
# my_dict = {idx: value for idx, value in enumerate(param_list)}
case_name = 'a.txt'
def change_type(case_name):
with open(case_name, 'r') as file:
param_list = [line.strip() for line in file]
my_dict = {idx: value for idx, value in enumerate(param_list)}
return my_dict
def bi_check(low, high, dict_test):
'''
:param low:
:param high:
:param dict_test:
:return:
'''
print('low-------------------------------', low)
print('high------------------------------', high)
if low + 1 >= high:
return
mid = (low + high) // 2
print('mid is ', mid)
print('value is',dict_test[mid])
# 执行命令后,返回pass 或 fail的结果
# 单次执行命令需要提供的参数是 所有需要去二分的数据
mid_result = bin_check(dict_test, mid)
# 根据执行结果,去重新定界二分的范围。
if mid_result == 'pass':
high = mid
print(mid, ':pass')
if mid_result == 'fail':
low = mid
print(mid, ':fail')
print('----------------------------------------------------------------------end')
bi_check(low, high, dict_test)
# 参数放在txt文件里,转换成字典类型。
dict_test = change_type(case_name)
print(dict_test)
low = 0
high = len(dict_test) - 1
bi_check(low, high, dict_test)
二分脚本-自己使用
最新推荐文章于 2024-06-23 22:06:32 发布