Ad
  • Custom User Avatar
  • Custom User Avatar

    Your constant issue closing is less than favourable. But don't worry, specially for you I found an identical kata to justify my "rant".

  • Default User Avatar

    If you are claiming a duplicate, then cite the kata which is being duplicated.

  • Custom User Avatar
  • Custom User Avatar

    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.

  • Custom User Avatar

    I have taken the liberty of fixing this issue for you. Replacing assertEquals with assertApproxEquals 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 an assertEquals 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.)

  • Custom User Avatar

    @nigelramdial Thanks for taking the time to respond to my feedback and improve this Kata :D

    ... I'll take my time to research exactly what the floating point error is ...

    I've just found a question asked on StackOverflow regarding floating point precision which you may (or may not) find useful :)

    ... and understand how your solution fixed my kata before I dive in and change the code

    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 of 2.00000000000004 and an expected value of 2 to pass but would cause 2.004 to fail when compared against 2; 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 :)

    Would I be able to create a duplicate of the kata to test that I have amended it correctly ...

    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 ;)

  • Custom User Avatar

    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.

  • Custom User Avatar

    That's a codewars platform problem, not a kata problem.

  • Custom User Avatar

    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:

    function assertFuzzyEquals(actual, expected) {
      Test.expect(expected === 0 ? Math.abs(actual) <= 1e-12 : Math.abs((expected - actual) / expected) <= 1e-12, "Failed asserting that actual value " + actual + " is sufficiently close to expected value " + expected + " (accepted relative error: 1e-12)");
    }
    

    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.:

    assertFuzzyEquals(areaOfCircle(1), Math.PI);
    assertFuzzyEquals(areaOfCircle(2), 4 * Math.PI);
    assertFuzzyEquals(areaOfCircle(1.5), 2.25 * Math.PI);
    
  • Custom User Avatar

    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.