Cash register test flaw?

In the instructions: “Return {status: "OPEN", change: [...]} , with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.”

Test #2 illustrates that change should only contain nonzero orders.
20 - 19.5 = [["QUARTER", 0.5]]

Test #3 illustrates that change should be returned in descending order.
100 - 3.26 = [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]

Based on the stated instructions and the previous examples, Test #6 should look like this, and this is what my code produces, which is correct.
20 - 19.5 = [["PENNY", 0.5]]

However, the stated expected result for Test #6 is in direct violation of the instructions and of Tests #2 and #3.
20 - 19.5 = [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]

Please explain. I’m pretty close to adding an if clause at the beginning of my code for this specific case just to pass, since as far as I can tell this is a flaw in the test and my code is correct.

The instructions say:

Return {status: "CLOSED", change: [...]} with cash-in-drawer as the value for the key change if it is equal to the change due.

In this case you are returning cid which has fields for every value.

direct violation of the instructions and of Tests #2 and #3.

Only if you ignore that #2 and #3 are status “OPEN” and expect a different return value.

Should it be that way? I don’t know. Would I have had a consistent return object for all cases? Probably. But welcome to the world of computing. I often get specs that I think are not ideal. Sometimes you just have to do them.

I’m pretty close to adding an if clause at the beginning of my code for this specific case just to pass

Don’t do that. But I would have an if clause for the condition that gives status CLOSED. That, you should definitely do.

since as far as I can tell this is a flaw in the test and my code is correct.

Look, we’ve all been there. We all have been frustrated. We’ve all thought, “my code is perfect, the only possible explanation is that [whatever] is broken”. Keep in mind that this challenge and these tests have been around for years and have been done by thousands of people.

And this is a tough challenge. A lot of people get caught up on this one. It is frustrating. But that is part of being a developer. They don’t pay us well because it is easy.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.