我是编程和编写python代码以检查给定值是否在范围内的新手。
从流量生成器,我得到了tx和rx数据包。对于rx数据包,我添加或取消了阈值,然后继续进行我的测试用例。
例如,如果tx = 2000且rx为2000,阈值为10,那么我只想在rx为1990至2010时继续进行测试。
我写了如下代码:
lower_range_exp_packet = tx_stat - threshold
higher_range_exp_packet = tx_stat + threshold
if rx_stat in range(int(lower_range_exp_packet),int(higher_range_exp_packet)):
log.info('The traffic test is pass as expected ...')
但是只是考虑是否有一种最简单或更Python的方式来做到这一点,而不是计算边界。
您可以执行以下操作:
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 ...')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句