A snapshot can be compared against any value with <= or >=.
This can be used to create a upper/lower bound for some result.
The snapshot value can be trimmed to the lowest/largest valid value.
defgcd(x,y):# use Euclidean Algorithmiterations=0whiley:iterations+=1x,y=y,x%yreturnabs(x),iterationsdeftest_gcd():result,iterations=gcd(12,18)assertresult==snapshot(6)assertiterations<=snapshot(12)
defgcd(x,y):# use Euclidean Algorithmiterations=0whiley:iterations+=1x,y=y,x%yreturnabs(x),iterationsdeftest_gcd():result,iterations=gcd(12,18)assertresult==snapshot(6)assertiterations<=snapshot(3)
Warning
This should not be used to check for any flaky values like the runtime of some code, because it will randomly break your tests.
The same snapshot value can also be used in multiple assertions.