Uh oh!
There was an error while loading. Please reload this page.
Add algorithm for testing Project Euler solutions - #2471
Conversation
Uh oh!
There was an error while loading. Please reload this page.
cclauss
commented
Sep 24, 2020
I put the PR in DRAFT mode. (Kind like beta) ;-) |
Co-authored-by: Christian Clauss <cclauss@me.com>
dhruvmanila
commented
Sep 24, 2020
Extra ideas: Should we keep the answers in a separate file in the Do we need additional information in our logs like |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cclauss
commented
Sep 24, 2020
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. |
dhruvmanila
commented
Sep 24, 2020
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" |
cclauss
commented
Sep 24, 2020
Let's run and fail fast just like |
dhruvmanila
commented
Sep 24, 2020
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. |
cclauss
commented
Sep 24, 2020
It takes 40 seconds to run. |
Uh oh!
There was an error while loading. Please reload this page.
- Renamed file so that it isn't picked up by pytest - Fail fast on validating solutions through Travis CI
TravisBuddy
commented
Sep 24, 2020
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: c5c89b70-feac-11ea-b444-3dcc0bd866ab |
dhruvmanila
commented
Sep 24, 2020
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 |
TravisBuddy
commented
Sep 24, 2020
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: 8df1c1d0-fead-11ea-b444-3dcc0bd866ab |
cclauss
commented
Sep 24, 2020
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. |
dhruvmanila
commented
Sep 24, 2020
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 |
Uh oh!
There was an error while loading. Please reload this page.
cclauss
commented
Sep 24, 2020
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 |
dhruvmanila
commented
Sep 24, 2020
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. |
Uh oh!
There was an error while loading. Please reload this page.
dhruvmanila
commented
Sep 25, 2020
Hi @cclauss, Can you take a look at this? Thanks! 😁
|
TravisBuddy
commented
Sep 25, 2020
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. |
dhruvmanila
commented
Sep 26, 2020
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? |
TravisBuddy
commented
Sep 26, 2020
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.
dhruvmanila
commented
Sep 27, 2020
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 |
TravisBuddy
commented
Sep 27, 2020
Hey @dhruvmanila, TravisCI finished with status TravisBuddy Request Identifier: e2767590-00ef-11eb-a257-6fde496095bb |
dhruvmanila
commented
Sep 27, 2020
I fixed long error messages into one line like before and now Travis CI will exit if this script fails. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Add custom print function to print all the error messages at the end of all the tests - Let Travis skip if this failed
dhruvmanila
commented
Sep 28, 2020
I removed the patch for printing the error messages and using That's weird. Why did Travis start two builds? |
cclauss
left a comment
There was a problem hiding this comment.
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.
dhruvmanila
commented
Sep 28, 2020
@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.pyfile 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_scriptsection forProject Eulerbuild.The use case for imported modules:
solution()functionsolution()function requires a positional argumentCurrently all the logs goes into the filename described in
LOG_FILENAMEconstant, 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}.