Debian Codegraph @

tests/benchmarks/test_calculate_distance_meters.py

raw symbols SCIP
1 from pytest_codspeed import BenchmarkFixture
2
3 from bluetooth_data_tools import calculate_distance_meters
4
5 # Close: ratio < 1, takes the pow(ratio, 10) branch.
6 _CLOSE_POWER = -4
7 _CLOSE_RSSI = -3
8
9 # Far: ratio > 1, takes the 0.89976 * pow(ratio, 7.7095) + 0.111 branch.
10 _FAR_POWER = -59
11 _FAR_RSSI = -60
12
13 # Zero rssi short circuits to None before any pow call.
14 _ZERO_POWER = 59
15 _ZERO_RSSI = 0
16
17
18 def test_calculate_distance_meters_close(benchmark: BenchmarkFixture) -> None:
19 benchmark(lambda: calculate_distance_meters(_CLOSE_POWER, _CLOSE_RSSI))
20
21
22 def test_calculate_distance_meters_far(benchmark: BenchmarkFixture) -> None:
23 benchmark(lambda: calculate_distance_meters(_FAR_POWER, _FAR_RSSI))
24
25
26 def test_calculate_distance_meters_zero(benchmark: BenchmarkFixture) -> None:
27 benchmark(lambda: calculate_distance_meters(_ZERO_POWER, _ZERO_RSSI))