Skip to content

luhn: Update example and add more tests#253

Merged
petertseng merged 1 commit intoexercism:masterfrom
gibfahn:luhn-tests
Feb 9, 2017
Merged

luhn: Update example and add more tests#253
petertseng merged 1 commit intoexercism:masterfrom
gibfahn:luhn-tests

Conversation

@gibfahn
Copy link
Copy Markdown
Contributor

@gibfahn gibfahn commented Jan 29, 2017

The luhn test suite didn't cover a lot of cases, including:

  • Strings of zeros
  • Non-alphabetic characters
  • Numbers which are only valid if you reverse the string

This adds those tests and updates the example to properly reject symbols (and check that the sum isn't zero).

Let me know if I'm doing something wrong!

EDIT: FYI I was previously using !c.is_whitespace() rather than c != ' '. I switched because technically other whitespace like \t and \n isn't allowed by the letter of the rules.

@IanWhitney
Copy link
Copy Markdown
Contributor

Thanks for the contribution! For most of our exercises we use the canonical test data defined in the x-common repo.

If we're going to improve Luhn's test suite, we should start by changing the canonical test file. Then all the tracks can implement the improved tests.

@gibfahn
Copy link
Copy Markdown
Contributor Author

gibfahn commented Feb 9, 2017

exercism/problem-specifications#522 has now landed, I've updated this, PTAL.

Comment thread exercises/luhn/example.rs Outdated
@@ -1,5 +1,6 @@
pub fn is_valid(candidate: &str) -> bool {
if candidate.chars().any(|c| c.is_alphabetic()) || candidate.chars().count() == 1 {
if input.chars().filter(|c| c.is_digit(10)).take(2).count() <= 1 ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you seem to have intended to change the input's name to input, but didn't make the same change in the argument. I believe if you were to do that, the tests could pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad, copying from my solution (which used input) to example, I forgot to change the name back. Hopefully fixed.

Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

righto, think we are doing well. I think just one small change and we can get this to compile and then merge it?

The luhn test suite didn't cover a lot of cases, including:
 - Strings of zeros
 - Non-alphabetic characters
 - SINs which are only valid if you remember to reverse the string
 - A 9 in a doubled position (9 * 2 - 9 should equal 9 not 0)
 - " 0" (invalid as there's only 1 digit)

This adds those tests and updates the example to properly reject symbols.
Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

OK, seems faithful to x-common. There is a chance it will change due to exercism/problem-specifications#523, but until then let's get these in front of students, eh?

@petertseng petertseng merged commit f259c37 into exercism:master Feb 9, 2017
@gibfahn gibfahn deleted the luhn-tests branch February 9, 2017 23:23
ErikSchierboom pushed a commit to ErikSchierboom/rust that referenced this pull request Jan 26, 2021
…#253)

Closes exercism#253

* Create parallel-letter-frequency.md

Initial list with concept level abstraction of common elements used for solving `parallel-letter-frequency`.

* Update with specific concurrency concepts separate

To-do: implement an example for each concurrency concept
ErikSchierboom pushed a commit to ErikSchierboom/rust that referenced this pull request Jan 27, 2021
…#253)

Closes exercism#253

* Create parallel-letter-frequency.md

Initial list with concept level abstraction of common elements used for solving `parallel-letter-frequency`.

* Update with specific concurrency concepts separate

To-do: implement an example for each concurrency concept
ErikSchierboom pushed a commit to ErikSchierboom/rust that referenced this pull request Jan 29, 2021
Closes exercism#253

* Create parallel-letter-frequency.md

Initial list with concept level abstraction of common elements used for solving `parallel-letter-frequency`.

* Update with specific concurrency concepts separate

To-do: implement an example for each concurrency concept
ErikSchierboom pushed a commit to ErikSchierboom/rust that referenced this pull request Jan 29, 2021
Closes exercism#253

* Create parallel-letter-frequency.md

Initial list with concept level abstraction of common elements used for solving `parallel-letter-frequency`.

* Update with specific concurrency concepts separate

To-do: implement an example for each concurrency concept
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