Skip to content

Commit

Permalink
Fix: if "db" mode and hz is 0 return 0 not inf
Browse files Browse the repository at this point in the history
  • Loading branch information
4lm committed Sep 27, 2019
1 parent 522b027 commit 55ad863
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions itu_r_468_weighting/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ def r468(frequency_hz: Union[int, float], khz_option: str, returns: str) -> floa
If parameter `khz_option` is not equal to `1khz` or `2khz`.
"""

if frequency_hz > 0:
if frequency_hz >= 0:
pass
elif frequency_hz == 0:
return inf
else:
raise ValueError

Expand All @@ -70,9 +68,9 @@ def r468(frequency_hz: Union[int, float], khz_option: str, returns: str) -> floa

if returns == "db":
if khz_option == "1khz":
return DB_GAIN_1KHZ + 20 * log10(r_itu)
return 0.0 if r_itu == 0.0 else DB_GAIN_1KHZ + 20.0 * log10(r_itu)
elif khz_option == "2khz":
return DB_GAIN_2KHZ + 20 * log10(r_itu)
return 0.0 if r_itu == 0.0 else DB_GAIN_2KHZ + 20.0 * log10(r_itu)
else:
raise ValueError
elif returns == "factor":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="itu-r-468-weighting",
version="2.0.2",
version="2.0.3",
description="A zero dependency Python ITU-R 468 noise weighting filter (1 kHz and 2 kHz)",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_weighting_filter_r468.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_value_lt_0_that_must_raise_value_error(hz, khz_option, returns):
(0, "2khz", "factor"),
],
)
def test_value_of_0_that_must_return_inf(hz, khz_option, returns):
assert r468(hz, khz_option, returns) == inf
def test_hz_value_of_0_must_return_0(hz, khz_option, returns):
assert r468(hz, khz_option, returns) == 0.0


@pytest.mark.parametrize(
Expand Down

0 comments on commit 55ad863

Please sign in to comment.