-
Notifications
You must be signed in to change notification settings - Fork 20
Testing #61
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
Testing #61
Conversation
|
Thanks, the parametrization is a very nice improvement compared to #60! Why did you change the tolerance of There are some minor coding style issues, could you please have a look at the output of this? |
tests/test_util.py
Outdated
| ((1,1,-1), (np.pi / 4, np.arccos(-1/np.sqrt(3)), np.sqrt(3))), | ||
| ((-1,1,-1), (np.arctan2(1,-1), np.arccos(-1/np.sqrt(3)), np.sqrt(3))), | ||
| ((1,-1,-1), (-np.pi / 4, np.arccos(-1/np.sqrt(3)), np.sqrt(3))), | ||
| ((-1,-1,-1), (np.arctan2(-1,-1), np.arccos(-1/np.sqrt(3)), np.sqrt(3))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When having a list with one entry per line, it's considered good style to add a final comma to the last line, even though this is not strictly necessary. This makes it easier to add new lines later. It also makes it easier to re-arrange the lines if that's desired at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback. I will explore pycodestyle to correct the coding style.
about assert_allclose(), I had a precision higher than the default so I decided to exploit it.
tests/test_util.py
Outdated
| import pytest | ||
| import sfs | ||
|
|
||
| test_data = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we might add more tests for ùtil` in the future the name of the array should be choosen more specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted! I will change it to reflect the test it is referenced in.
I see, but in fact you were reducing the precision, because the default is I was quite confused when I discovered the different default values some time ago ... |
|
@mgeier Thank you very much for this observation. The error I made was not setting rtol =0. The function works with both rtol (tolerance per unit value) and atol (overall tolerance). In my case atol is more important to me not rtol. I am still struggling to understand pycodestyle. I do not know how to interpret the output, can you give more insight please. z.B. |
Are you sure? I thought that Anyway, I would only use a non-default value if there is a good reason.
Well first of all you should read PEP8: https://www.python.org/dev/peps/pep-0008/
The two numbers after the file name are the line and column numbers, respectively. But you can just look at all commas and check if there is proper whitespace after them. Some editors also have the ability to check this in the background and show the warnings similar to a spell checker. Probably there is a plugin available for your editor? |
|
I didn't properly understand the reason why the coordinates of the image sources are ordered the way they are ordered. The actual values are correct, I just don't why it is arranged the way it is. I think if I properly understands this, it will help in extending to more than the first image sources. Also, I did not understand why the format for the wall count is the way it is. Can anyone give me a little insight so I do not run into too much problems in the future? |
|
Thanks for the new commits! I didn't see your older commits f1cbe7e and a0637ef. In the future, please write a comment when you have done some suggested changes, to make sure that everyone notices them. I've squashed and merged your older commits and made an additional commit changing the test function names from Can you please rebase your new commit on the new I didn't look into Writing the tests already paid off, because you found a bug in the |
mgeier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few comments.
tests/test_util.py
Outdated
|
|
||
|
|
||
| @pytest.mark.parametrize('linear, decibel', db_data) | ||
| def testdb(linear, decibel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please start test function names with test_.
tests/test_util.py
Outdated
|
|
||
|
|
||
| db_data = [ | ||
| ((0), -math.inf), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parentheses in (0) have no effect. They are especially not creating a tuple, which it looks like you wanted to do?
See https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/intro-python.ipynb#Tuples
tests/test_util.py
Outdated
|
|
||
|
|
||
| db_data = [ | ||
| ((0), -math.inf), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use -np.inf, then you don't need the separate math import.
tests/test_util.py
Outdated
| def testdb(linear, decibel): | ||
| try: | ||
| x, is_power = linear | ||
| except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like mixing tuples and numbers in the parameters.
Why don't you split this into two test functions, one for power=False and the other for power=True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could even re-use the test data in this case and just divide the expected result by 2 for power=True.
tests/test_util.py
Outdated
| is_power = False | ||
|
|
||
| d = sfs.util.db(x, is_power) | ||
| assert_allclose(d, decibel, rtol=1e-2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's a good idea to use such a big tolerance.
I think it would be better if you just calculate some values with the required accuracy and then use the default tolerances to test it.
Or is there a reason not to do that?
|
@mgeier Thank you for the feedback. I have implemented your suggestions. |
|
Thanks for the update! And thanks for fixing the Now there are some |
.gitignore
Outdated
| .eggs/ | ||
| sfs.egg-info/ | ||
| .cache | ||
| .vscode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know about .cache but .vscode is the project folder of visual studio code. I personally also use it but I don't know what the policy on adding stuff like this to the .gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess different people use different policies.
I like to keep the file short and clean. Others like horribly complicated ones like https://github.com/github/gitignore/blob/master/Python.gitignore.
I think it should only contain things that are relevant to the current project and programming language(s).
User-dependent things like editor settings and stuff like this should IMHO go into your own global ignore file, see https://help.github.com/articles/ignoring-files/#create-a-global-gitignore and https://stackoverflow.com/a/7335487/.
For example, I have those in my global ignore list:
tags
core
octave-core
.*.swp
*.un~
.ipynb_checkpoints/
.ycm_extra_conf.pyc
__pycache__/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't intend to put it as part of a pull request. Sorry!
tests/test_util.py
Outdated
| (10*4, (10+6.02059991327962)), | ||
| (10*0.5, (10-3.01029995663981198)), | ||
| (10*0.1, (10-10)), | ||
| (10*0.25, (10-6.02059991327962396)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better now.
But I don't really understand why you are using 10*... and 10+.... Can you please explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This are kind of known identities when converting from linear scale to dB.
Such that when you double in linear scale = + 3(approx.) in dB etc.
I put in the code so that it is obvious to anyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see.
So why don't you drop the 10?
You could just use
...
(0.5, -3.01029995663981198),
...
(2, 3.010299956639813),
...IMHO it would also be easier to read if you sort the lines.
Also, you really don't need that many test cases, I think about half of them would be enough.
But you could make a separate test function to test one case where the function raises an error, namely using a negative input.
tests/test_util.py
Outdated
| @pytest.mark.parametrize('linear, decibel', db_data) | ||
| def test_db_power(linear, decibel): | ||
| d = sfs.util.db(linear) | ||
| assert_allclose(d, 2*decibel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required by PEP8, but I personally would prefer spaces around the * here.
|
|
||
| @pytest.mark.parametrize('linear, decibel', db_data) | ||
| def test_db_amplitude(linear, decibel): | ||
| d = sfs.util.db(linear, True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't match the function name.
Also, you should not use a bare True or False as a function argument (unless probably if it's the only argument).
You should use it as a keyword argument, i.e. you should use power=True (except you should actually use that in test_db_power()).
tests/test_util.py
Outdated
| (10*4, (10+6.02059991327962)), | ||
| (10*0.5, (10-3.01029995663981198)), | ||
| (10*0.1, (10-10)), | ||
| (10*0.25, (10-6.02059991327962396)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see.
So why don't you drop the 10?
You could just use
...
(0.5, -3.01029995663981198),
...
(2, 3.010299956639813),
...IMHO it would also be easier to read if you sort the lines.
Also, you really don't need that many test cases, I think about half of them would be enough.
But you could make a separate test function to test one case where the function raises an error, namely using a negative input.
|
I've taken most of this and used it in #78. |
What does this PR do?
Tests cart2sph & sph2cart functions