-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
generators: convert generators to use auto extract #567
Conversation
5dc1462
to
db28d13
Compare
def workload | ||
[ | ||
"phrase = '#{input}'", | ||
" result = Pangram.pangram?(phrase)", | ||
" #{assertion} result, \"#{message}\"" | ||
" #{assert} result, \"#{message}\"" |
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.
Can do message.inspect
here and get rid of the \"
s
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.
Doesn't work here (at least straight substitution doesn't). The interpolation in message
would also need adjusting.
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.
you're right. 👍
@@ -54,6 +59,6 @@ def test_hyphenated | |||
|
|||
def test_bookkeeping | |||
skip | |||
assert_equal 2, BookKeeping::VERSION | |||
assert_equal 3, BookKeeping::VERSION |
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.
Not sure the changes here warrant a version bump.
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.
It added a test, hence the version bump.
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.
ok, I missed that
exercises/anagram/anagram_test.rb
Outdated
@@ -137,6 +104,6 @@ def test_capital_word_is_not_own_anagram | |||
|
|||
def test_bookkeeping | |||
skip | |||
assert_equal 2, BookKeeping::VERSION | |||
assert_equal 3, BookKeeping::VERSION |
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.
unnecessary version bump?
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.
There are changed tests. Shouldn't that mean the version is updated?
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.
Which tests changed? I can't find any that have changed input
or expected
values.
The commit that does the version update should just include the bits of the file that caused that version upgrade.
These are being hidden by the rest of the noise in the commit due to formatting changes. (which don't require a version bump.)
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.
Ah, you are right. In this case, just the names changed.
exercises/anagram/anagram_test.rb
Outdated
detector = Anagram.new('master') | ||
anagrams = detector.match(["stream", "pigeon", "maters"]) | ||
assert_equal ["maters", "stream"], anagrams.sort | ||
assert_equal ["maters", "stream"], Anagram.new('master').match(["stream", "pigeon", "maters"]).sort |
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.
I strongly prefer the previous 3-line version of all these tests.
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.
Interesting. I strongly prefer the one line version. With the three line version, I have to mentally assemble the test; with the one line version, it is all right there.
I go to multiple lines on tests that are too complex to mentally wrangle by reading a single line (like the tests I wrote for Generator::CaseValues
. But if I can do it in one or two lines, I prefer it.
How would you feel about a two line version?
anagrams = Anagram.new('master').match(["stream", "pigeon", "maters"])
assert_equal ["maters", "stream"], anagrams.sort
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.
It is worse than both the 3 and 1 line versions.
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.
ROFL!
The usual 3 line pattern for tests is
expected = ...
actual = ...
assert_equal expected, actual
These 3 liners cause cognitive friction for me because they are 3 liners that violate that pattern.
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.
4 would probably be best since you can use another line for expected
The main issue here is that we want to prioritize educational value over expert comprehension.
1 line:
assert_equal ["gallery", "largely", "regally"], Anagram.new('allergy').match(["gallery", "ballerina", "regally", "clergy", "largely", "leading"]).sort
At my day job I would be fine with the 1 line version as everyone knows the test framework and can maintain a consistent test style, and we are not trying to work out how to implement a solution by looking at the tests.
On Exercism I want to make sure that things are clear to people who may not be as familiar with Minitest and even Ruby.
Multi line:
detector = Anagram.new('allergy')
anagrams = detector.match(["gallery", "ballerina", "regally", "clergy", "largely", "leading"])
expected = ["gallery", "largely", "regally"]
assert_equal expected, anagrams.sort
The multi line version uses variable naming to reveals the intention of the individual elements of the one line assertion. Note that the values used for detector
,anagrams
and expected
are all vary by test.
This provides the information one needs to derive the code to pass the test in a clear and consistent manner.
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.
Makes sense to me! I'll change it.
eca7663
to
ee75656
Compare
Just load the alpha_cases file direcly, we know where it is.
test/fixtures/metadata/exercises/alpha/canonical-data.json We are the only user of this fixture data.
Renamed 'gamma' to 'complex'.
Add test that template_values loads problem cases Remove commented out code. Make everything that loads AlphaCase(s) clean up after itself. Undefine AlphaCase(s) during teardown. Remove redundant setup. Check for both classes. Add tests for class based test generation squash Remove TODO comment
all generators converted to use auto extraction in exercism#567
removed tests that are now redundant
ee75656
to
c56bd33
Compare
Big thanks @hilary for all your work on this! ❤️ ⭐ 👍 |
Motivation and Context
I converted all generators to use auto extraction (#568) so we don't need to maintain support for the old
proc
extraction technique.Description
(Commits 19d34af and e839613 are part of #568)
How Has This Been Tested?
In all cases,
rake test
passes.In all cases, regenerating the tests produces either the same tests (when the data has not changed) or the desired tests (for updated data)
Types of changes
Updates and fixes
References and Closures
Checklist:
My change requires a change to the documentationI have updated the documentation accordingly.I have added tests to cover my changes.