我是编程和编写 python 代码来检查给定值是否在一个范围内的新手。从流量生成器,我得到 tx 和 rx 数据包。对于 rx 数据包,我添加或否定阈值并继续我的测试用例。例如,如果 tx = 2000 且 rx 为 2000,阈值为 10,那么我只想在 rx 为 1990 到 2010 时继续我的测试。我编写了如下代码:lower_range_exp_packet = tx_stat - thresholdhigher_range_exp_packet = tx_stat + thresholdif rx_stat in range(int(lower_range_exp_packet),int(higher_range_exp_packet)): log.info('The traffic test is pass as expected ...')但只是想是否有一种最简单或更pythonic的方法来代替计算边界..请建议。
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
你可以这样做:
lower_range_exp_packet = tx_stat - threshold
higher_range_exp_packet = tx_stat + threshold
if lower_range_exp_packet <= rx_stat <= higher_range_exp_packet:
log.info('The traffic test is pass as expected ...')
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
以下代码将有助于满足您的条件:
lower_range_exp_packet = tx_stat - threshold
higher_range_exp_packet = tx_stat + threshold
if rx_stat >= lower_range_exp_packet and rx_stat <= higher_range_exp_packet:
log.info('The traffic test is pass as expected ...')
添加回答
举报
0/150
提交
取消