Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
There are slight formatting issues in the description of the methods, making especially the description of
takehard to read.addnegative is justtakepositive. I'd do away with either ( one ), and allow negative numbers, before doing away with zeroes.But I like zero and null cases.
That's a really thoughtful point, and you're absolutely right in terms of good API design — user errors (wrong pin, insufficient funds) and programmer errors (malformed input, negative amounts) are conceptually different, and in a real-world API they'd deserve distinct, purpose-built exception types.
For this kata specifically, I kept everything under a single exception type on purpose, mainly to keep the difficulty appropriate for a 7 kyu level and make it approachable to as many solvers as possible — introducing custom exception hierarchies felt like it would shift the focus away from the core exercise (constructors, validation, basic class design) and add complexity that isn't really the point here.
It's a fair trade-off to question though, and I appreciate you laying out the reasoning so clearly — it's given me something to think about for future katas where the domain modeling itself might be more central to the exercise.
If this is an exercise about APIs, I am not a fan how all incorrect scenarios boil down to identical outcome of
IllegalArgumentException(andValueError). Out of all possible error conditions, the only situations which deserveIllegalArgumentExceptionmight be negative amounts, and malformed PINs (i.e. not four digit ones). Situations like incorrect PIN or withdrawal of insufficient funds would deserve a better, more meaningful signal. Such values are legal, they fit domain of the operation, they are just potentially incorrect in given situation. They are user errors, not program errors. They should be, ideally, represented by application-specific exception types.Thanks for the input! This was actually an intentional design choice on my part — passing 0 to
addortakeis a no-op (nothing gets added, nothing gets withdrawn), so I didn't see a strong reason to forbid it. It also let me reuse the same validation logic for the constructor's balance and for amounts inadd/take, sincebalance = 0is explicitly allowed.That said, if you feel this is important enough to change, I'm happy to update the test cases to raise a ValueError on zero as well — just let me know!
Thanks for pointing this out - that's a fair catch. You're right, the description should be self-contained and I shouldn't rely on solvers figuring out return types (or the lack thereof) from test failures.
I've updated the description to explicitly state:
checkreturns an int (the balance)adddoesn't return anythingtakereturns an int (the withdrawn amount)This applies to both the Java and Python versions now. Appreciate you flagging it - let me know if anything else is still unclear!
Your test results expect both the "add" and "take" methods to process a zero amount. In my opinion, a zero amount passed to either of these methods should throw a ValueError.
All of the requirements (including required return values from each function) should be made clear in the description. It should not be necessary to infer these from the test failure messages.
Thank you for taking the time to leave this feedback — I really appreciate it! I'm still fairly new to creating katas, so comments like this are genuinely helpful for me to improve.
Regarding the constructor argument order: you're right, and I've fixed it. The Python version now uses
Safe(pin, balance=0)instead of the originalSafe(balance, pin).I'll admit I haven't fully figured out how translations/descriptions work across languages yet, but I did my best to update the description to reflect the fix. Let me know if anything still looks off!
Also added random tests as you suggested — thanks again for pointing that out, I wasn't aware that was expected as a standard practice here.
Safe(pin,balance)would seem to be better design ifbalanceis optional.If this is only intended to make the kata more difficult, please consider what you're doing there: passing artificially bad design off to your solvers to handle, when completely unnecessary.
Random tests are not optional.
At least some people ( including me ) will downvote your kata, when solved, if it has no random tests. I'd suggest you unpublish your kata now and add random tests, to prevent people from downvoting it simply for not having random tests; they may or may not come back after you've added them to update their vote.
Hello! I am a Codewars bot, and I reviewed your kata for common authoring mistakes.
Click to see the review
Commonly occurring issues
@Testmethods and no section with randomly generated cases. For example, tests liketestConstructorWithBalanceAndCheck,testAddIncreasesBalance, andtestTakeMoreThanBalanceThrowsin the submission tests all use hardcoded values only, making it possible to hardcode a solution without being caught by random tests.assertEquals(100, safe.check("1234"));,assertThrows(IllegalArgumentException.class, () -> safe.check("0000"));, and others in theSafeTestclass have neither assertion messages nor human‑readable test titles that mention the inputs, which makes it harder to diagnose failures from the output alone.SafeTestdo not specify any execution order (@TestMethodOrderor@TestClassOrderare not used), so methods liketestConstructorWithBalanceAndCheck,testAddIncreasesBalance, andtestNegativeAmountThrowsmay run in any order instead of the recommended sequence of basic fixed tests, additional fixed tests, and then random tests.Other potential problems
Note: the issues below are not an effect of studying any guidelines, and they are purely an effect of evaluation of AI. They are very likely to be inaccurate or inapplicable. Use your own judgement, and when in doubt, ask the community before fixing!
double(e.g.public double check(String pin)andpublic double take(int amount, String pin)), but both the solution stub, complete solution, and tests useintreturn types for these methods. This type mismatch will confuse users and can cause compilation problems if they follow the description literally.amount"must be positive" foraddandtake, but submission tests liketestZeroAmountDoesNotThrowexpectsafe.take(0, "1234")to return0andsafe.add(0, "1234")to be allowed, and the complete solution’svalidateAmounttreats0as valid. This is a direct conflict between the specification and the tests/solution behavior.Please mind that I am not a very smart bot, and you should verify my remarks with any resources available for kata authors and translators:
#help-authoringchannel of Codewars DiscordThis comment is hidden because it contains spoiler information about the solution