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.
Still a duplicate.
Your constant issue closing is less than favourable. But don't worry, specially for you I found an identical kata to justify my "rant".
If you are claiming a duplicate, then cite the kata which is being duplicated.
Duplicate.
Given the author didn't connect in some time, I've made some changes:
The function that generates the sides could return 0.
10 random tests seemed too few. I've changed it to 50.
I have taken the liberty of fixing this issue for you. Replacing
assertEquals
withassertApproxEquals
did the trick. This is undocumented, and may be new since this issue was raised. (After all, who knows how long undocumented features may have been present?) Writing anassertEquals
wrapper has always been possible, but is more work.Before it can be approved, you will need a lot more ratings, because those "Not much" or "Somewhat" satisfieds count against you heavily. They were probably based on this issue, but may never be changed. It is therefore preferable to fix issues sooner rather than later, to prevent amassing bad ratings for things easily fixed. (This issue was entirely predictable of course. It isn't new. Would have been better if the kata hadn't suffered from it in the first place.)
@nigelramdial Thanks for taking the time to respond to my feedback and improve this Kata :D
I've just found a question asked on StackOverflow regarding floating point precision which you may (or may not) find useful :)
That's perfectly fine; my (extremely complicated-looking) customized assertion method makes use of the fact that floating point precision causes very tiny errors only, sometimes less than
1 x 10^(-12)
, to compare two floats and see if they are close enough. For example, this assertion method would allow and actual value of2.00000000000004
and an expected value of2
to pass but would cause2.004
to fail when compared against2
; reason being that the first actual value is probably caused by a different order of operations (for example) but the second actual value is clearly a calculation error. Hope this helps in explaining the assertion :) Note, however, that I haven't tested the code snippet I provided to you above yet so I'm not sure if it contains any typos or such - feel free to inform me if necessary :)Well, no, at least not automatically. I guess you could create a new Kata and manually copy-paste every section into your new Draft Kata and do your testing there but make sure you don't publish it - otherwise, a lot of "This is a duplicate" issues will be raised on your duplicate Kata ;)
Thanks for taking the time to give me such thorough advice, much appreciated. Think I'll sit down and try to fix this when I have time. Yes I am new to authoring Kata (and to Javascript) so I'll take my time to research exactly what the floating point error is and understand how your solution fixes my kata before I dive in and change the code. Would I be able to create a duplicate of the kata to test that I have amended it correctly before 'breaking' this original one? Thanks for this, I had no idea this was the case and will change it once I understand fully.
That's a codewars platform problem, not a kata problem.
Seeing as you are new to authoring Kata on Codewars, you may not be aware of this - and it is perfectly normal, but you should never just use
Test.assertEquals
to compare two floating point values, reason being that there is floating point error in JavaScript which means that if a user calculates the same result from the same decimals in a different order, he/she may arrive upon a very slightly different decimal which is not their fault at all. For floating point values, use this assertion instead:To use this assertion, first copy and paste the code snippet above into the "Preloaded" section of your Kata, then in the Test Cases, just call it like any other test method, e.g.:
I'm a newbie so sorry if I've wasted your time but I can't define the "language" (Javascript) in the dropdown menu. Just keeps unselecting and then telling me "undefined language not supported" when I attempt a test.