Repository navigation
isbn-verifier: implement exercise in Java track - #1004
Conversation
|
Hmm, not too sure why the build failed - if anyone knows please tell me 🙂 The log says about Also, what I have noticed in implementing |
This seems... weird. I can take a look this evening! r.e. the descriptions: I'm not usually strict about mapping canonical data descriptions to test names, but improving the canonical data descriptions is always worthwhile! I'd recommend opening an issue for discussion in https://github.com/exercism/problem-specifications to see what others think :) |
|
I think I've seen it give that error before. That time I restarted the build and it was fine. So I've tried restarting the build now to see if that works again :) But it would be good to know why it happened either way... |
|
Spooky 😱 |
|
🎉 Hooray! Very odd. Just looking back at my implementation, I think I have misunderstood the exercise, so I might tidy it up before it gets merged, if that is ok? |
|
Sure, we haven't reviewed it yet so that's not a problem. Just add a comment here when you think it's ready for review :) (you could also put "don't merge" or "not ready for review" in the title if you want) |
|
Ok, I think that this is now all ready from my point of view 🙂 |
|
Great, I'll try to find time to review it later today :) One thing I can quickly see is that since it has difficulty 4 it should have starter implementation (see the POLICIES doc) and I don't think you've added any? |
|
Oops! I had it locally as a 5 before dialling it back to 4 - change now made, thanks for the reminder 🙂 |
FridaTveit
left a comment
There was a problem hiding this comment.
This looks great @sjwarner-bp! :)
I've made a few comments but they're mostly minor things. Feel free to disagree with me or ask questions :)
| "topics": [ | ||
| "integers", | ||
| "loops", | ||
| "strings" |
There was a problem hiding this comment.
@stkent I saw you recently did a PR to corrent the lengths of uuids. How long do they have to be? Is that documented anywhere? I can't see it in the exercise configuration document...
There was a problem hiding this comment.
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is the correct pattern; the UUID used here is too long:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
0c5fcd83-01a5-3880-2784-277ff6cba7b5e51c3b0
If using configlet to generate UUIDs, note that configlet generated invalid UUIDs up until v3.6.0; as of v3.6.1 it generates correct ones.
There was a problem hiding this comment.
Perfect, I've updated my configlet
|
|
||
| private String isbn; | ||
|
|
||
| boolean isValid(String s) { |
There was a problem hiding this comment.
Single letter variable names are generally bad practice (with some exceptions like indices or coordinates) because they don't convey much information about what the variable is. What about stringToVerify? :)
|
|
||
| boolean isValid(String s) { | ||
|
|
||
| this.isbn = s.replace("-", ""); |
There was a problem hiding this comment.
I don't think this should be a class variable since it's only used in this method :)
|
|
||
| if (isbn.length() != 10) { | ||
| return false; | ||
| } else { |
There was a problem hiding this comment.
You don't need the else here since you return in the if block :)
|
|
||
| @Test | ||
| public void validIsbnNumber() { | ||
| Assert.assertEquals(true, isbnVerifier.isValid("3-598-21508-8")); |
There was a problem hiding this comment.
You can use assertTrue and assertFalse instead of assertEquals, that will give better error messages when the tests fails :)
There was a problem hiding this comment.
This still needs to be changed to assertTrue :) And you could do a static import so that you don't have to do Assert.assertTrue:
import static org.junit.Assert.assertTrue;
assertTrue(something, somethingElse)
:)
| } | ||
| } | ||
|
|
||
| if (Character.isDigit(isbn.charAt(9))) { |
There was a problem hiding this comment.
I would absorb this into the previous loop (just check if i == isbn.length - 1 && isbn.charAt(i) == 'X'). But it doesn't matter too much, it's pretty clear either way :) So if you want to keep it separate then that's fine :)
I would use isbn.length() - 1 instead of 9 though, to keep it consistent with the other loop and to prevent the use of "magic" numbers that can confuse anyone reading the code :)
| return false; | ||
| } | ||
|
|
||
| if (total % 11 == 0) { |
There was a problem hiding this comment.
This can be simplified to return total % 11 == 0 :)
| return false; | ||
| } else { | ||
| for (int i = 0; i < isbn.length() - 1; i++) { | ||
| if(Character.isDigit(isbn.charAt(i))) { |
There was a problem hiding this comment.
I would extract isbn.charAt(i) into a local variable since you're using it twice :)
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking great @sjwarner-bp! Thanks for making those changes so quickly :) I've left a few more minor comments but it's very nearly ready to merge! :)
| boolean isValid(String stringToVerify) { | ||
|
|
||
| String isbn; | ||
| isbn = stringToVerify.replace("-", ""); |
There was a problem hiding this comment.
You could do this on one line:
String isbn = stringToVerify.replace("-", "");
| } | ||
|
|
||
| for (int i = 0; i < isbn.length() - 1; i++) { | ||
| char currentDigit = isbn.charAt(i); |
There was a problem hiding this comment.
Maybe currentChar? Either that or use currentDigitVal and finalDigit later to be consistent :)
| @@ -0,0 +1,7 @@ | |||
| class IsbnVerifier { | |||
|
|
|||
| boolean isValid(String s) { | |||
There was a problem hiding this comment.
This one should also be stringToVerify :)
|
|
||
| @Test | ||
| public void validIsbnNumber() { | ||
| Assert.assertEquals(true, isbnVerifier.isValid("3-598-21508-8")); |
There was a problem hiding this comment.
This still needs to be changed to assertTrue :) And you could do a static import so that you don't have to do Assert.assertTrue:
import static org.junit.Assert.assertTrue;
assertTrue(something, somethingElse)
:)
It happened again! 😱 |
|
Strange... I'll restart it :) |
FridaTveit
left a comment
There was a problem hiding this comment.
This looks great! Thanks for adding this exercise @sjwarner-bp, it's a great addition to the track :)
Implementation of isbn-verifier, as per
problem-specifications.Reviewer Resources:
Track Policies