-
-
Notifications
You must be signed in to change notification settings - Fork 46.3k
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
Add algorithm for testing Project Euler solutions #2471
Add algorithm for testing Project Euler solutions #2471
Conversation
I put the PR in DRAFT mode. (Kind like beta) ;-) |
Co-authored-by: Christian Clauss <cclauss@me.com>
Extra ideas: Should we keep the answers in a separate file in the Do we need additional information in our logs like |
This is looking awesome. The logging is just for us to develop the tests. Don't make the logs fancy -- we will get rid of them when we are done. Once we land this PR, files will either pass the test or we will flag them as inadequate. |
Alright. What are you thinking to do next?
So, the tests will fail if the requirements aren't satisfied, printing the appropriate message for the person to debug? I'm a bit confused about what do you mean by "flag them as inadequate" |
Let's run and fail fast just like |
Oh lol, I forgot to change the |
So... pytest "test discovery" finds all files called test_xxx.py or xxx_test.py and runs them as tests. So pytest is automatically running the file which means that you do not need to explicitly run the file in .travis.yml. |
It takes 40 seconds to run. |
- Renamed file so that it isn't picked up by pytest - Fail fast on validating solutions through Travis CI
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: c5c89b70-feac-11ea-b444-3dcc0bd866ab |
This commit is going to fail as for what I wanted to show when you mentioned:
https://travis-ci.com/github/TheAlgorithms/Python/jobs/390693925#L249 |
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: 8df1c1d0-fead-11ea-b444-3dcc0bd866ab |
That is why we are in draft mode. ;-) OK... So not how do we read the function signature so that we know how many input parameters a function needs? For each directory, we will need some sample data to pass into those functions that take parameters. |
The input parameters come from the questions. We can have something like if the function requires arguments, which would be in the case of In the other case, we need to have those input parameters and if required, which we will know if we get a |
from collections import namedtuple q_and_a = namedtuple("q_and_a", "question answer") ANSWERS = { Just do a few to see if we can make it work. |
Not possible. Just take this problem as an example: https://projecteuler.net/problem=4 Here they are asking for the largest palindrome made from the product of two 3-digit numbers. Now, how do we define an input parameter to this question? The solutions submitted have We do know the answer but that's not my point. We cannot define an input parameter to such questions. The Just take a look at the size of this input parameter lol: https://projecteuler.net/problem=13 |
If solution() needs no parameter then question=None like I did with number 1 |
So you're saying we provide the parameters? What do you suggest the parameter for https://projecteuler.net/problem=4 be? The solutions submitted does ask for a parameter. |
Hi @cclauss, Can you take a look at this? Thanks! 😁
|
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: 83621750-ff03-11ea-b444-3dcc0bd866ab |
OK... Let's force default args so that On eulertest.py#L21, my modification would be:
If it would help, send me an email so we can do a videoconf. |
Alright, I did it and also added all the answers according to https://github.com/luckytoilet/projecteuler-solutions
I already did this right from the start 😁 I'll send you the email but is there anything else to discuss? |
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: 01f25b50-ffe7-11ea-9882-0125ab0f75bf |
- As we want to fail fast on testing solutions, we need to test using this script first before we use tests written by the author. - As pytest stops testing as soon as it receives a traceback, we need to use pytest-subtests to tell pytest to test all the iterations for the function with given parameters.
Alright, that's not so good in terms of information plus it went on executing the other script, I will put it in Any idea about how to capture just the message part of the exception in the |
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: e2767590-00ef-11eb-a257-6fde496095bb |
I fixed long error messages into one line like before and now Travis CI will exit if this script fails. |
- Add custom print function to print all the error messages at the end of all the tests - Let Travis skip if this failed
I removed the patch for printing the error messages and using That's weird. Why did Travis start two builds? |
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.
Awesome work @dhruvmanila Congratulations! 💯
@poyea @AnupKumarPanwar @dynamitechetan This is an awesome submission made by @dhruvmanila. Well written, modern Python which delivers the superpower of validating the answer to every Euler solution in our repository. It scans every subdirectory and finds and runs the proposed Euler solution and then lists out any algorithm that does not return the correct answer.
I would like to propose that we add @dhruvmanila as a maintainer of TheAlgorithms.
@cclauss Thank you for giving me the opportunity to work on it. 😇 |
* Add file for testing Project Euler solutions * Remove the importlib import * Update project_euler/solution_test.py Co-authored-by: Christian Clauss <cclauss@me.com> * Small tweaks to project_euler/solution_test.py * Test Project Euler solutions through Travis * Improved testing for Project Euler solutions: - Renamed file so that it isn't picked up by pytest - Fail fast on validating solutions through Travis CI * Update validate_solutions.py * Use namedtuple for input parameters and answer - Remove logging - Remove unnecessary checks for PROJECT_EULER_PATH as Travis CI picks up the same path * Fix flake8 errors: line too long * Small tweaks to validate_solutions.py * Add all answers & back to using dictionary * Using pytest for testing Project Euler solutions - As we want to fail fast on testing solutions, we need to test using this script first before we use tests written by the author. - As pytest stops testing as soon as it receives a traceback, we need to use pytest-subtests to tell pytest to test all the iterations for the function with given parameters. * Print error messages in oneline format * Separated answers into a separate file: - Add custom print function to print all the error messages at the end of all the tests - Let Travis skip if this failed Co-authored-by: Christian Clauss <cclauss@me.com>
* Add file for testing Project Euler solutions * Remove the importlib import * Update project_euler/solution_test.py Co-authored-by: Christian Clauss <cclauss@me.com> * Small tweaks to project_euler/solution_test.py * Test Project Euler solutions through Travis * Improved testing for Project Euler solutions: - Renamed file so that it isn't picked up by pytest - Fail fast on validating solutions through Travis CI * Update validate_solutions.py * Use namedtuple for input parameters and answer - Remove logging - Remove unnecessary checks for PROJECT_EULER_PATH as Travis CI picks up the same path * Fix flake8 errors: line too long * Small tweaks to validate_solutions.py * Add all answers & back to using dictionary * Using pytest for testing Project Euler solutions - As we want to fail fast on testing solutions, we need to test using this script first before we use tests written by the author. - As pytest stops testing as soon as it receives a traceback, we need to use pytest-subtests to tell pytest to test all the iterations for the function with given parameters. * Print error messages in oneline format * Separated answers into a separate file: - Add custom print function to print all the error messages at the end of all the tests - Let Travis skip if this failed Co-authored-by: Christian Clauss <cclauss@me.com>
As described in #2463 (comment)
Currently in beta
Adding
solution_test.py
file for testing all the submitted solutions for Project Euler. The file will not be picked up by Travis CI and we will have to manually call it, maybe we can call it inbefore_script
section forProject Euler
build.The use case for imported modules:
solution()
functionsolution()
function requires a positional argumentCurrently all the logs goes into the filename described in
LOG_FILENAME
constant, we can change it to wherever we want it to go. The log looks like this (we can change it however we want):Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.