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

generators: convert generators to use auto extract #567

Merged
merged 61 commits into from
Apr 27, 2017

Conversation

hilary
Copy link
Contributor

@hilary hilary commented Apr 24, 2017

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)

  • generators I wrote myself:
    • Luhn
    • OCR numbers
    • Pig Latin
  • others
    • Acronym (updated)
    • All your base
    • Alphametics (generator was broken)
    • Anagram
    • Binary (generator was broken)
    • Beer Song
    • Bowling (generator was broken)
    • Bracket Push
    • Clock
    • Connect
    • Custom Set
    • Difference of squares
    • Dominoes
    • Gigasecond (updated, generator was broken)
    • Grains (generator was broken)
    • Hamming
    • Hello World
    • Isogram
    • Largest Series Product (updated)
    • Leap (updated)
    • Nth prime
    • Pangram
    • Queen attack (generator was broken)
    • Raindrops
    • RNA transcription
    • Roman numerals
    • Run length encoding (updated, generator was broken)
    • Say
    • Sieve
    • Tournament (generator was broken)
    • Transpose
    • Triangle (generator was broken)
    • Two Bucket (generator was broken)
    • Word Count
    • Wordy

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 documentation
  • My change relies on a pending issue/pull request
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@hilary hilary force-pushed the generate_problem_name_cases branch 2 times, most recently from 5dc1462 to db28d13 Compare April 24, 2017 05:16
@hilary hilary changed the title generators: auto extract cases from canonical data generators: convert generators to use auto extract Apr 24, 2017
def workload
[
"phrase = '#{input}'",
" result = Pangram.pangram?(phrase)",
" #{assertion} result, \"#{message}\""
" #{assert} result, \"#{message}\""
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I missed that

@@ -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
Copy link
Contributor

@Insti Insti Apr 24, 2017

Choose a reason for hiding this comment

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

unnecessary version bump?

Copy link
Contributor Author

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?

Copy link
Contributor

@Insti Insti Apr 24, 2017

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.)

Copy link
Contributor Author

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.

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

@Insti Insti Apr 24, 2017

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.

Copy link
Contributor Author

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

Copy link
Contributor

@Insti Insti Apr 24, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@Insti Insti Apr 25, 2017

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.

Copy link
Contributor Author

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.

hilary and others added 21 commits April 26, 2017 14:17
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
@hilary hilary force-pushed the generate_problem_name_cases branch from ee75656 to c56bd33 Compare April 26, 2017 21:32
@Insti Insti merged commit 6accd52 into exercism:master Apr 27, 2017
@Insti
Copy link
Contributor

Insti commented Apr 27, 2017

Big thanks @hilary for all your work on this! ❤️ ⭐ 👍

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.

2 participants