-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsignal_test.py
35 lines (28 loc) · 985 Bytes
/
wsignal_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Test wireless signal utility functions"""
from pytest import approx
from wsignal import dbm_to_watt, watt_to_dbm
def test_known_dbm_to_watt_results():
"""
Tests dbm to watt conversion with some manually verified examples.
"""
# by definition, 0dbm = 1mW
assert dbm_to_watt(0) == approx(1e-3)
assert dbm_to_watt(10) == approx(1e-2)
assert dbm_to_watt(20) == approx(1e-1)
assert dbm_to_watt(30) == approx(1)
assert dbm_to_watt(40) == approx(10)
def test_known_watt_to_dbm_results():
"""
Tests watt to dbm conversion with some manually verified examples.
"""
# by definition, 0dbm = 1mW
assert watt_to_dbm(1e-3) == approx(0)
assert watt_to_dbm(1e-4) == approx(-10)
assert watt_to_dbm(1) == approx(30)
def test_db_watt_conversion_reversible():
"""
Tests that converting from db to watt and back results in the
original db value.
"""
db = 10
assert watt_to_dbm(dbm_to_watt(db)) == approx(db)