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

Luhn with generator #559

Merged
merged 5 commits into from
Apr 21, 2017
Merged

Luhn with generator #559

merged 5 commits into from
Apr 21, 2017

Conversation

hilary
Copy link
Contributor

@hilary hilary commented Apr 21, 2017

Description

Added Generator for Luhn for new Luhn canonical data

Motivation and Context

The Luhn exercise had some weaknesses (exercism/problem-specifications#474) which have now been addressed via canonical data (exercism/problem-specifications#491).

How Has This Been Tested?

We ran rake test

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Applying canonical data

References and Closures

Checklist:

  • My change requires a change to the documentation.
    • The generate documentation needs some luuuuuv.
  • 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 added 2 commits April 20, 2017 17:02
Cases and template seem to be very simple, and may be used in
documenting this process.
@kotp
Copy link
Member

kotp commented Apr 21, 2017

Failing due to Ruby version not having sum method... being corrected soon.

Copy link
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

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

Looks good, it generates a correct looking test file which is the main thing.

class LuhnTest < Minitest::Test<% test_cases.each do |test_case| %>
def <%= test_case.name %>
<%= test_case.skipped %>
<%= test_case.assertion %> <%= test_case.work_load %>
Copy link
Contributor

Choose a reason for hiding this comment

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

test_case.workload should include the assertion.

So this line can be simplified to: <%= test_case.workload %>

index.zero? ? '# skip' : 'skip'
end

def assertion
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be made private as it is only needed by workload

@@ -6,13 +6,15 @@ def name
end

def work_load
%Q(Luhn.valid?("#{input}"))
%Q(#{assertion} Luhn.valid?("#{input}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

"#{input}"

This will work, but it's a good habit to use input.inspect which will handle input that contains quotes.

Nice usage of %Q though. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

'test_%s' % description.tr('- ', '__')
end

def work_load
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be workload

Copy link
Contributor

Choose a reason for hiding this comment

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

I've updated the documentation to help clarify this: #560

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 there a style guide somewhere (other than the README)? Because some of the exercises use work_load and others use workload. In fact, as long as it is the same in both example.tt and <exercise>_cases.rb it should work fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, just the README.
I've made a PR to rename the old occurrences to try and clear this up: #561

Copy link
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

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

Looks great. Nice work @hilary

@Insti Insti merged commit 348672a into exercism:master Apr 21, 2017
@Insti
Copy link
Contributor

Insti commented Apr 21, 2017

Thanks for doing this @hilary ❤️

It will be some non-deterministic amount of time until this change is visible as it requires Katrina to do a release to the live site, but that will probably happen sometime in the next day or two.

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.

3 participants