Skip to content

Add tests without modifying code #10740

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

Merged
merged 5 commits into from
Oct 22, 2023

Conversation

gio-puter
Copy link
Contributor

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

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

gio-puter and others added 4 commits October 20, 2023 16:47
Added doctest to largest_of_very_large_numbers.py
Added doctest to word_patterns.py
Added doctest to onepad_cipher.py
Added doctest to maths/largest_of_very_large_numbers.py
Added doctest to strings/word_patterns.py
Added doctest to ciphers/onepad_cipher.py
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 21, 2023
Copy link
Contributor

@imSanko imSanko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Different PR !! one PR can't change the entire stuff, so it should be one by one which becomes easy for the maintainers

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a few changes...

Traceback (most recent call last):
...
IndexError: list index out of range

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 11 to 22

>>> res(0, 5)
0

>>> res(3, 0)
1

>>> res(-1, 5)
Traceback (most recent call last):
...
ValueError: math domain error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
>>> 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([])

@algorithms-keeper algorithms-keeper bot added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Oct 21, 2023
@cclauss
Copy link
Member

cclauss commented Oct 21, 2023

@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 build output and see that they are running and none of these files is among our ten slowest running tests and then I can approve.

It would be easier to review is all the algorithms chosen were in the same directory.

@cclauss cclauss changed the title Contributes to #9943 Add tests without modifying code Oct 21, 2023
Added test to maths/largest_of_very_large_numbers
Added test to strings/word_patterns.py
Added test to ciphers/onepad_cipher.py
@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Oct 22, 2023
@gio-puter
Copy link
Contributor Author

Ok. Awesome. I went ahead and made the requested format changes and additions.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 22, 2023
@cclauss cclauss merged commit 0601b56 into TheAlgorithms:master Oct 22, 2023
@cclauss cclauss self-assigned this Oct 22, 2023
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* Contributes to TheAlgorithms#9943
Added doctest to largest_of_very_large_numbers.py
Added doctest to word_patterns.py
Added doctest to onepad_cipher.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Contributes to TheAlgorithms#9943
Added doctest to maths/largest_of_very_large_numbers.py
Added doctest to strings/word_patterns.py
Added doctest to ciphers/onepad_cipher.py

* Add tests without modifying code TheAlgorithms#10740
Added test to maths/largest_of_very_large_numbers
Added test to strings/word_patterns.py
Added test to ciphers/onepad_cipher.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants