# Community Puzzle: Simple Fraction to Mixed Number

My code was passing all tests, but only getting 62% on validation.
While writing this message I realized what was the mistake and got 100%.

I think all edge cases should be in the testcases, validation should only be for avoiding hardcoding. At least it’s usually the case on CodinGame.
What do you think?

Haha, I had an issue with 100% IDE and only 37% validators (I had an a*b to test the sign, and it appears the numbers of validator cases are quite big comparing to IDE’s -> int overflow )

2 Likes

All edge cases used in validators are present in test cases, except for big numbers maybe. I haven’t realized that it could be a problem and during beta stage nobody found this, and now that the puzzle is approved I cannot edit it anymore.

OK,

I had forgotten to ensure that zero isn’t negative.
There’s no test case with a negative zero (only divisions by zero), but apparently there’s three verifications with negative zeroes.
No big deal, anyway :).

Well, open test case “Zero” actually has a case of “-0/287” which checks for zero-sign-handling (but I agree that a counterpart of “0/-287” and also “-0/-287” could also be added there).

I remember running into the negative zero case, myself. I just checked, and my code (without the one-line fix that I added for that) works fine for -0/xxx, but fails for 0/-xxx. So works for all tests, but fails for all validators.

It’s worth noting for others who might run into the same problem. Unless / until this puzzle is changed, you should make sure that your code can properly handle zero divided by a negative number in order to properly pass all validators.

• danBhentschel

I’m having kind of the same issue. I got 87% as the last test in real environment fails, while all the IDE tests pass. I’ve checked the -0 case, and as I don’t explicitly print a - sign, also making sure to compare 0 with abs(num), I’m a bit lost about how to move forward. It would be helpful to get some kind of feedback from it. Is there many numbers in the last test, so the program times out? Is there some special cases which are not covered and the computation is wrong? If you’ve already figured out what you did wrong could you provide a custom test which could potentially highlight the flows in my code? Any help would be appreciated.

1 Like

Try the following test:

2
2/2
-2/2

Should output:

1
-1

• danBhentschel

Thank you, it passes fine. Also tried 2/-2 -1, -2/-2 1.

If you want to PM me your code, I can probably figure out where it falls down.

• danBhentschel

This could also be a big-number-error.
Now that the puzzle has been approved, these errors are popping up and I cannot edit the visible test cases anymore. If I could, I would add cases like this:

0/-174
-0/-174
999999/-999999
-999999/-999999
-999999/999999

as well as some more “big number” cases.

As an option, the last validation test could be added to visible test cases but in re-ordered form, so that it has the same fractions but in different order.

Thanks for sending me the code. MMMAAANNN is correct. You time out on big numbers. Try this test case:

10
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067
7338162/8696067

Should give:

2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689
2446054/2898689

Your code currently times-out on this.

• danBhentschel
1 Like

I’m stuck as well with the “some for sign handling” at validation phase. All the tests run smoothly, I am running short of ideas on where my mistake could be. What should be solutions for
0/-174
-0/-174
My understanding of the rules is that it should give zero in both case, but is it correct?

That is correct. Both should be zero.

• danBhentschel

Thanks, i made the same mistake :). how did you see the overflow?

By chance, I have moderation rights on community puzzles, and still had a link to the draft on my notifications, so I could peek to see how the validators look like ^^

I’m having the same issue, I’ve run every test I’ve seen here in the forum posts, big numbers and mixed negatives included, and they all come out correct… but I’m only getting 75% on the validation. Some more sign handling, and many random cases just won’t pass. I’ve racked my brain trying to figure out where the issue is. If anyone could help point me in the right direction, that would be super.

I will help out anyone who pm’s me with complete source code.

• danBhentschel

I’m at 100% IDE and stuck at the last validation case “many random cases”. I haven’t seen the pre-approved puzzle so no idea what’s in that test case. Any idea what I might have missed?

SOLVED: I forgot to check for the case where x / x = 1, that should be added to the test cases.

I have added that case to the tests, along with several other cases that have tripped up others in the past. Thanks for the suggestion.

• danBhentschel
1 Like