Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

added a test that breaks my solution

  • Loading branch information...
commit 6b313b765e33131f0c92bc0fbd638944d106ab05 1 parent dc4c729
@youngnh authored
6 tests/src/main/java/com/squareup/luhnybin/
@@ -82,6 +82,12 @@
test("long sequence of digits with no matches").sendAndExpect(nonMatchingSequence(1000));
+ for (int i = MIN_LENGTH; i <= MAX_LENGTH; i++) {
+ test("2 matching card numbers on same line")
+ .send(randomNumber(i) + nonMatchingSequence(i) + randomNumber(i))
+ .expect(mask(i) + nonMatchingSequence(i) + mask(i));
+ }
private void testFormatted(char delimeter) {
BIN  tests/target/luhnybin-1.0-SNAPSHOT.jar
Binary file not shown

2 comments on commit 6b313b7


Hi! Just FYI, I tested this change with my own implementations (Ruby and Dart) and my implementations too failed this test. Then I debugged it a little and found out that I'm happy with the way the implementations work.

The failure seems to be in the test. Because the digits allow for plenty (I counted 8) legal numbers.

The way I interpret the tests is that so long as there are legal overlapping numbers we should try to mask them out. Perhaps because due to randomness we can't know for sure where the numbers start and end. So long as the numbers are legal, mask them out, no matter how many of them are left.

According to my tests, all the digits in this new test should be masked out. Somehow.



You're right that this test is probably introducing overlapping valid numbers that should be XX'd out.

I was trying to get at the case where I had 2 credit card numbers on either side of some other random digits.

Maybe a clearer test would be replacing the nonMatchingSequence(i) with " phone: 867-5309 " or something similar, for the purposes of this coding excercise, you don't want those digits XX'd out. My implementation fails in that regard.

Please sign in to comment.
Something went wrong with that request. Please try again.