Skip to content
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

Merged
merged 7 commits into from
Nov 5, 2016

Conversation

Insti
Copy link
Contributor

@Insti Insti commented Oct 24, 2016

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.

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 = {}
Copy link
Contributor Author

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)
Copy link
Contributor Author

@Insti Insti Oct 24, 2016

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.

Copy link
Contributor

@moveson moveson Oct 28, 2016

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.
#
Copy link
Contributor Author

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 }
Copy link
Contributor Author

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.

@bmulvihill
Copy link
Contributor

This looks/works good to me!

@kotp
Copy link
Member

kotp commented Oct 25, 2016

@moveson will be helping with this, if I am reading the comments on his solution correctly.

@Insti
Copy link
Contributor Author

Insti commented Oct 25, 2016

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.

@kotp
Copy link
Member

kotp commented Oct 25, 2016

Place them at the end, so that by the time they are commenting out the skip it is apparent if they have a slow solution or not. Place a comment there near the skip that states perhaps they can submit their current solution, without the following tests having ran.

@bmulvihill
Copy link
Contributor

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.

@Insti
Copy link
Contributor Author

Insti commented Oct 29, 2016

Waiting on @moveson to submit the improved example.rb

@moveson
Copy link
Contributor

moveson commented Oct 31, 2016

The new example.rb is ready. What's the next step?

@Insti
Copy link
Contributor Author

Insti commented Oct 31, 2016

@moveson create a new pull request that only updates the example.rb file.
Once that's there I can do what needs to be done to merge it into this one.

@moveson
Copy link
Contributor

moveson commented Nov 2, 2016

This is ready when you are. See PR #477.

@kotp kotp added ready and removed in progress labels Nov 2, 2016
@Insti Insti added in progress and removed ready labels Nov 2, 2016
@Insti
Copy link
Contributor Author

Insti commented Nov 2, 2016

I still need to merge in @moveson's example.rb and remove the test case filtering from the *_cases.rb file. I will do this when I get some time over the next few days.

@Insti
Copy link
Contributor Author

Insti commented Nov 2, 2016

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.)
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@Insti Insti changed the title [alphametics] Ignore long running tests in the common test data. [alphametics] Warn about long running tests in the common test data. Nov 2, 2016
@Insti Insti merged commit 5ac769e into exercism:master Nov 5, 2016
@Insti Insti deleted the alphametics_generator branch November 5, 2016 09:54
@Insti Insti removed the in progress label Nov 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants