Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flake8 #62

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Fixed tests, uncommented hz_to_midi
  • Loading branch information
jblsmith committed Nov 20, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bb6c151300a9b6401d29d9e40cf0a794d3f4a328
8 changes: 4 additions & 4 deletions toymir/freq.py
Original file line number Diff line number Diff line change
@@ -38,12 +38,12 @@ def hz_to_midi(frequencies):
# Oh hey, it's Part 5! You could uncomment this implementation,
# and then the tests will pass!

# less_than_zero = (np.asanyarray(frequencies) <= 0).any()
less_than_zero = (np.asanyarray(frequencies) <= 0).any()

# if less_than_zero:
# raise ValueError('Cannot convert a hz of zero or less to a period.')
if less_than_zero:
raise ValueError('Cannot convert a hz of zero or less to a period.')

# return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69
return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69


def hz_to_period(frequencies):
18 changes: 12 additions & 6 deletions toymir/tests/test_toymir.py
Original file line number Diff line number Diff line change
@@ -18,16 +18,22 @@ def test_midi_to_hz_array():
# These are the two tests you should uncomment!


# def test_hz_to_midi_float():
# expected = 69
# assert toymir.hz_to_midi(440.0) == expected
def test_hz_to_midi_float():
expected = 69
assert toymir.hz_to_midi(440.0) == expected


# def test_hz_to_midi_array():
# expected = [57, 69, 81]
# assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected)
def test_hz_to_midi_array():
expected = [57, 69, 81]
assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected)


def test_hz_to_midi_throws_if_zero_or_less():
# The test will pass if code inside the `with` block raises a ValueError!
with pytest.raises(ValueError):
toymir.hz_to_midi(0)
toymir.hz_to_midi(-1)

# Hello! You could add the missing test for test_hz_to_midi here!