Add tests without modifying code#10740
Conversation
Added doctest to largest_of_very_large_numbers.py Added doctest to word_patterns.py Added doctest to onepad_cipher.py
for more information, see https://pre-commit.ci
Added doctest to maths/largest_of_very_large_numbers.py Added doctest to strings/word_patterns.py Added doctest to ciphers/onepad_cipher.py
imSanko
left a comment
There was a problem hiding this comment.
Use Different PR !! one PR can't change the entire stuff, so it should be one by one which becomes easy for the maintainers
ciphers/onepad_cipher.py
Outdated
| Traceback (most recent call last): | ||
| ... | ||
| IndexError: list index out of range | ||
|
|
|
|
||
| >>> res(0, 5) | ||
| 0 | ||
|
|
||
| >>> res(3, 0) | ||
| 1 | ||
|
|
||
| >>> res(-1, 5) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: math domain error | ||
|
|
There was a problem hiding this comment.
It is better if the tests do not require extra scrolling when someone is reading the code. If they want to read all the tests, they can take the time to do so but often readers will want to look at the function signature and then jump straight to the code. Keeping the tests in tight block will allow them them to study the function signature and the code without too much visual distraction.
| >>> res(0, 5) | |
| 0 | |
| >>> res(3, 0) | |
| 1 | |
| >>> res(-1, 5) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: math domain error | |
| >>> res(0, 5) | |
| 0 | |
| >>> res(3, 0) | |
| 1 | |
| >>> res(-1, 5) | |
| Traceback (most recent call last): | |
| ... | |
| ValueError: math domain error |
| >>> get_word_pattern("") | ||
| '' | ||
| >>> get_word_pattern(" ") | ||
| '0' |
There was a problem hiding this comment.
Please put the tests that work correctly first and then afterward the ones that raise exceptions.
Also, please add:
>>> get_word_pattern(1)
>>> get_word_pattern(1.1)
>>> get_word_pattern([])
|
@imSanko You are correct but in this case, adding tests without changing code makes this one easy to review. I can read through the tests and see if they make sense and hit some corner cases. Then I can look at the It would be easier to review is all the algorithms chosen were in the same directory. |
Added test to maths/largest_of_very_large_numbers Added test to strings/word_patterns.py Added test to ciphers/onepad_cipher.py
|
Ok. Awesome. I went ahead and made the requested format changes and additions. |
Describe your change:
Contributes to #9943
Added doctest to maths/largest_of_very_large_numbers.py
Added doctest to strings/words_patterns.py
Added doctest to ciphers/onepad_cipher.py
Checklist: