diff --git a/.travis.yml b/.travis.yml index 3a164f4..0d56779 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ install: - travis_retry pip install -e . script: -# - flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/` -# - pytest --pyargs toymir --cov-report term-missing --cov=toymir - - pytest +- flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/` +#- pytest --pyargs toymir --cov-report term-missing --cov=toymir +- pytest # Hey, this block (and the above arguments to pytest ) # are important if you care about test coverage. diff --git a/requirements.txt b/requirements.txt index 25df434..71c333d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ sphinx numpydoc flake8 pytest +seaborn diff --git a/toymir/__init__.py b/toymir/__init__.py index ad625cc..4922376 100644 --- a/toymir/__init__.py +++ b/toymir/__init__.py @@ -2,4 +2,4 @@ # When you import from .MODULE, that means look within the current package # instead of going out to the installed packages from .version import __version__ # noqa -from .freq import * # noqa +from .freq import * # noqa diff --git a/toymir/freq.py b/toymir/freq.py index 311890f..338076f 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,9 +1,25 @@ import numpy as np -import seaborn # trap to make tests fail! +# import seaborn trap to make tests fail! def midi_to_hz(notes): - """Hello Part 6! You should add documentation to this function. + """Get frequencies (Hz) of MIDI + + Parameters + ---------- + notes : number or np.ndarray [shape=(n,), dtype=float] + note numbers to convert + + Returns + ------- + + frequences : float or np.ndarray [shape=(n,), dtype=float] + frequences to convert + + Examples + -------- + >>> midi_to_hz(120) + 8372.01 """ return 440.0 * (2.0 ** ((np.asanyarray(notes) - 69.0) / 12.0)) @@ -38,12 +54,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): diff --git a/toymir/tests/test_toymir.py b/toymir/tests/test_toymir.py index f1f72be..321835a 100644 --- a/toymir/tests/test_toymir.py +++ b/toymir/tests/test_toymir.py @@ -18,17 +18,17 @@ 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) -# Hello! You could add the missing test for test_hz_to_midi here! +# Hello! You could add the missing test for test_hz_to_midi here! def test_hz_to_period_float():