Skip to content

[WIP] isbn-verifier: implement exercise#890

Closed
eulercb wants to merge 5 commits intoexercism:masterfrom
eulercb:feature/isbn-verifier
Closed

[WIP] isbn-verifier: implement exercise#890
eulercb wants to merge 5 commits intoexercism:masterfrom
eulercb:feature/isbn-verifier

Conversation

@eulercb
Copy link
Copy Markdown

@eulercb eulercb commented Oct 14, 2017

A detailed description of this exercise can be found here.

TODO:

  • ISBN-10 verifier
  • ISBN-10 generator from a starting ISBN (bonus task)
  • ISBN-13 generator (bonus task)
  • Suggested changes

@ilya-khadykin ilya-khadykin changed the title isbn-verifier: implement exercise [WIP] isbn-verifier: implement exercise Oct 15, 2017
Copy link
Copy Markdown
Contributor

@jamesmcm jamesmcm left a comment

Choose a reason for hiding this comment

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

Just some notes, overall it looks good.

Perhaps the extra tasks you suggest should be split out in to separate exercises?

Comment thread exercises/isbn-verifier/example.py Outdated
int(isbn[8:9]) * 2) % 11

if check_digit == 10:
return 'X'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is quite a lot of code for a small task, I'd recommend something like:

import string

def verify_isbn(isbn):
    handleX = lambda x: 10 if x == 'X' else x
    nums = [int(handleX(x)) for x in isbn if x in string.digits+'X']
    return(sum([x*(10-ind) for ind, x in enumerate(nums)]) % 11 == 0)

self.assertIs(verify('3598215078X'), False)

def test_invalid_isbn_without_check_digit(self):
self.assertIs(verify('3-598-21507'), False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here you can use AssertTrue and AssertFalse instead of AssertIs.

I.e.:

    def test_verify_isbn_example_with_X_spaces(self):
        self.assertTrue(isbn_verifier.verify_isbn('955 20 3051 X'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

assertFalse won't fail the test if the tested method returns None in comparison with assertIs

Consider this:

import unittest

tc = unittest.TestCase()

tc.assertFalse(None) # passes
tc.assertIs(None, True) # fails as expected

Do you see the difference, @jamesmcm?

So, I think it's better to use assertIs even if readability suffers a bit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a good point, seems like strange behaviour from the unittest module.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, especially considering that bool(None) returns False meaning that None is Falsy

Copy link
Copy Markdown
Contributor

@N-Parsons N-Parsons Oct 16, 2017

Choose a reason for hiding this comment

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

@m-a-ge, your example code is asserting that None is Falsey, so passing is the expected behaviour - bool(None) is False, so assertFalse(None) should pass (and does).

import unittest

tc = unittest.TestCase()

tc.assertFalse(None)  # Passes, since None is Falsey
tc.assertTrue(None)   # Fails because None is not Truthy

tc.assertIs(None, False)  # Fails because None is not False
tc.assertIs(None, True)   # Fails because None is not True

In theory, there's nothing wrong with using assertTrue and assertFalse in exercise tests, but the presence of the latter will cause some tests to pass when no code is implemented, and so these could confuse some people. Using assertIs creates another slight issue, in that it forces learners to return booleans, even though they may expect to be able to use Truthy and Falsey statements instead. I'd consider assertIs the lesser of two evils.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@N-Parsons thanks for clarification

Comment thread config.json
"uuid": "7961c852-c87a-44b0-b152-efea3ac8555c",
"slug": "isbn-verifier",
"core": false,
"unlocked_by": null,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would consider this a much, much easier difficulty. Perhaps put it after the RNA Transcription exercise?

@N-Parsons
Copy link
Copy Markdown
Contributor

N-Parsons commented Oct 16, 2017

@jamesmcm, the implementation of the two additional tests is fairly simple, so I don't think they should go into a separate exercise.

ISBN-10 to ISBN-13: Prepend "978" and calculate the new checksum (by the ISBN-13 method).
ISBN-10 generator: Calculate the checksum, if the ISBN is valid, return it, otherwise correct the last digit and return it.

These tests are clearly quite easy extensions if the checksum calculation is implemented as a separate function to the validation.

@eulercb eulercb changed the title [WIP] isbn-verifier: implement exercise isbn-verifier: implement exercise Oct 29, 2017
Copy link
Copy Markdown
Contributor

@N-Parsons N-Parsons 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 overall, but it could do with some additional information in the README (and .meta/hints.md so that it doesn't get lost in future). You also seem to have some extra changes to your config.json that will need to be removed before merging.

I also commented on the choice of function names, but I'd like to hear your thoughts on this.

Comment thread config.json
"strings",
"arrays",
"integers",
"parsing"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like you've accidentally included some changes for a different exercise.


Which proves that the ISBN is valid.

### Submitting Exercises
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be at heading level 2 (## Submitting Exercises).

pass


def isbn13_generator_from_isbn10(isbn10):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

generate_isbn13_from_isbn10 might be a better function name?

pass


def isbn_generator(isbn):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

generate_isbn might be a better function name? I think function names should be more descriptive of what they do than what they are.

(3 * 10 + 5 * 9 + 9 * 8 + 8 * 7 + 2 * 6 + 1 * 5 + 5 * 4 + 0 * 3 + 8 * 2 + 8 * 1) mod 11 = 0

Which proves that the ISBN is valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add something here (and to .meta/hints.md) to explain that we are also expecting implementations of an ISBN10 generator and an ISBN13 generator? It will also need to explain how the conversion from ISBN10 to ISBN13 works, and how to do the ISBN13 checksum calculation.

@eulercb eulercb changed the title isbn-verifier: implement exercise [WIP] isbn-verifier: implement exercise Oct 30, 2017
@cmccandless
Copy link
Copy Markdown
Contributor

@eulercamposbarros Canonical-data has been updated in /exercism/problem-specifications/#993

@stale
Copy link
Copy Markdown

stale Bot commented Nov 23, 2017

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the abandoned label Nov 23, 2017
@stale stale Bot closed this Nov 30, 2017
@pheanex
Copy link
Copy Markdown
Contributor

pheanex commented Dec 21, 2017

Would it be okay for everyone If I continue from where @jamesmcm left off?
I'd really like to see this exercise online.

@cmccandless
Copy link
Copy Markdown
Contributor

@pheanex Actually the PR was started by @eulercamposbarros. In any case, as this has been closed due to being abandoned, the original author has effectively forfeited his/her claim on the work, so feel free to pick it up!

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.

6 participants