-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
[alphametics] Warn about long running tests in the common test data. #469
Conversation
Ignore test cases based on the complexity of the expected result. Hardcoded commented out versions of the hard(er) tests along with instructions on why you might want to enable them. Refactored lib/alphametics_cases.rb. Use the common generator method names. Tidied up expected value string generation code. Re-generate tests based on version based on proposed changes. exercism/problem-specifications#425 Update `example.rb` to pass the current version of tests.
actual = Alphametics.new.solve('A == B') | ||
assert_equal(expect, actual) | ||
input = 'A == B' | ||
expected = {} |
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.
Invalid solutions now expect an empty hash rather than a nil
value.
This may be controversial, but I strongly believe that a method should always return the same type of object.
assert_equal(expect, actual) | ||
input = 'I + BB == ILL' | ||
expected = { 'B' => 9, 'I' => 1, 'L' => 0 } | ||
assert_equal expected, Alphametics.solve(input) |
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.
Was: Alphametics.new.solve(input)
Now: Alphametics.solve(input)
Instantiating an object is unnecessary, so it now uses a instance class method.
Edit: It's NOT using an instance method.
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.
In the final test, 'AND + A + STRONG + OFFENSE + AS + A + GOOD = DEFENSE'
, the =
should be ==
. Also, in the commentary, optimsing
should be optimising
.
# These tests have been commented out due their long runtime. If you are | ||
# interested in optimsing your solution for speed these are a good tests to | ||
# try. | ||
# |
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 'long' tests are ignored by the test case generator but are hardcoded here for reference.
It would also be possible (but more complicated) to generate them (I think I forgot that's what I started out trying to do.)
row = row.merge('index' => i) | ||
AlphameticsCase.new(row) | ||
end | ||
|
||
# The example algorithm takes a long time to solve these. | ||
testcases.reject { |testcase| (testcase.expected||{}).size > 7 } |
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.
Test cases are ignored based on how many letters there are in the expected output.
Things started slowing down on my computer after 7 so that's where I drew the line.
This looks/works good to me! |
@moveson will be helping with this, if I am reading the comments on his solution correctly. |
The reason the tests were commented out is because it was taking the example solver too long to solve them during CI checks. Once @moveson contributes his example.rb we will no longer need to comment out the "slow" tests since his solver is fast enough to solve them quickly. Should they still remain commented out in order to help the people who are trying to solve the problem? By including them, we make it a much harder problem by implying that you also need to solve the 8 and 10 letter cases, but by having them commented out we have a simpler problem but with some easily accessible extensions to suggest in the solution reviews on the site. My vote would be to keep them commented out. |
Place them at the end, so that by the time they are commenting out the |
I like @kotp's solution. It keeps the template the same as the others, and it follows the simple pattern of uncommenting the skip to open a test up. |
Waiting on @moveson to submit the improved |
The new |
@moveson create a new pull request that only updates the |
This is ready when you are. See PR #477. |
I still need to merge in @moveson's |
Re-add the "slow" test cases with a comment about them being slow.
I've pulled in @moveson's solver and re-added the slow testcases with comments warning that they might be slow. @bmulvihill can you have a look over it and see if it all looks ok now? |
|
||
# The obvious algorithm can take a long time to solve this puzzle, | ||
# but an optimised solution can solve it fairly quickly. | ||
# (It's OK to submit your solution without getting this test to pass.) |
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.
Is the wording of this comment OK?
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.
Yes.
Ignore test cases based on the complexity of the expected result.
Hardcoded commented out versions of the hard(er) tests along with
instructions on why you might want to enable them.
Refactored lib/alphametics_cases.rb.
Use the common generator method names.
Tidied up expected value string generation code.
Re-generate tests based on version based on proposed changes.
exercism/problem-specifications#425
Update
example.rb
to pass the current version of tests.