Synced ISBN-Verifier to Problem Specifications
Updated exercise instructions Accepted new additional test case Regenerated test file and verified example solution continues to pass.
This commit is contained in:
@@ -8,7 +8,7 @@ numbers. These normally contain dashes and look like: `3-598-21508-8`
|
||||
The ISBN-10 format is 9 digits (0 to 9) plus one check character (either a digit or an X only). In the case the check character is an X, this represents the value '10'. These may be communicated with or without hyphens, and can be checked for their validity by the following formula:
|
||||
|
||||
```text
|
||||
(x1 * 10 + x2 * 9 + x3 * 8 + x4 * 7 + x5 * 6 + x6 * 5 + x7 * 4 + x8 * 3 + x9 * 2 + x10 * 1) mod 11 == 0
|
||||
(d₁ * 10 + d₂ * 9 + d₃ * 8 + d₄ * 7 + d₅ * 6 + d₆ * 5 + d₇ * 4 + d₈ * 3 + d₉ * 2 + d₁₀ * 1) mod 11 == 0
|
||||
```
|
||||
|
||||
If the result is 0, then it is a valid ISBN-10, otherwise it is invalid.
|
||||
|
||||
@@ -21,6 +21,9 @@ description = "valid isbn with a check digit of 10"
|
||||
[3ed50db1-8982-4423-a993-93174a20825c]
|
||||
description = "check digit is a character other than X"
|
||||
|
||||
[9416f4a5-fe01-4b61-a07b-eb75892ef562]
|
||||
description = "invalid check digit in isbn is not treated as zero"
|
||||
|
||||
[c19ba0c4-014f-4dc3-a63f-ff9aefc9b5ec]
|
||||
description = "invalid character in isbn is not treated as zero"
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ class IsbnVerifierTest(unittest.TestCase):
|
||||
def test_check_digit_is_a_character_other_than_x(self):
|
||||
self.assertIs(is_valid("3-598-21507-A"), False)
|
||||
|
||||
def test_invalid_check_digit_in_isbn_is_not_treated_as_zero(self):
|
||||
self.assertIs(is_valid("4-598-21507-B"), False)
|
||||
|
||||
def test_invalid_character_in_isbn_is_not_treated_as_zero(self):
|
||||
self.assertIs(is_valid("3-598-P1581-X"), False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user