Yet another ISBN edge case found

I had a mentoring session on ISBN Verifier. The student replaced X$ with the string 10 so that the isbn length became 11. The student does not check for length greater than 10.

Instead of adding 1 * isbn[9] to the sum, the remaining digits isbn.substring(9) (from index 9 to the end) parsed to an int are added.

None of the existing test cases failed.

Can we add a new case:

{
  "uuid": "...",
  "description": "only one check digit is allowed",
  "property": "isValid",
  "input": {
    "isbn": "3-598-21508-96"
  },
  "expected": false
}

In this case, the weighted sum of the “359821508” digits plus the “check number” 96 is divisible by 11, but there are too many check digits.

1 Like

This was my mentoring feedback:

For this solution, your algorithm allows invalid input. Because you’re not checking that the input length is greater than 10, then '3-598-21508-96' improperly passes: the weighted sum of the “359821508” digits plus 96 is divisible by 11. But this is not a valid ISBN.

Your code does not obey this constraint from the instructions:

The ISBN-10 format is 9 digits (0 to 9) plus one check character (either a digit or an X only).

2 Likes

Ah yes. That’s a code mistake currently not caught. I would be in favour of adding a test.

I’m also in favor.

1 Like

I’m conflicted on this ;) This case seems reasonable, but I’m wary of the “trending towards entropy” and adding a test case for every which buggy implementation that shows up.

2 Likes

These are not input-unknown cases, but they catch real incorrect implementations. I think it’s good that we add those test cases and we should remain extremely vigilant to not add complexity or defensive programming practices (like you say: doesn’t need to be exhaustive).

With the trend of less people asking for mentorship, I think this is the best way to help our students!

2 Likes

So I have 2½ mentors agreeing :smile:

I’ll round up and go ahead with a PR.

2 Likes

I share @SleeplessByte position on catching more wrong implementations but not adding new constraints / functional rules. So +1 for me to add the test.

1 Like

And merged.

2 Likes