Draft

Which path is the shortest?

Description
Loading description...
Geometry
Algebra
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • FArekkusu Avatar

    Calculating distance between 2 points is not a novel kata idea.

  • JohanWiltink Avatar

    The CodeWars Test framework has an undocumented assertApproxEquals, which does more or less exactly what Donald's wrapper does.

    I have edited the first three fixed submit tests to use this.

    Hope you don't mind.

  • aweleshetu Avatar

    Your test for rounding still has flaws. Hope you fix that.

  • FrankK Avatar

    Hi, the kata is easy but OK.

    The rounding is not correct. It rounds for instance 18.444524 to 18.45 instead of 18.44. I had to round twice (first to 18.445 and then to 18.45) to get it fixed.

    NOTE:

    The problem could have been avoided if you did not use the 'anti-pattern' for your random tests to:

    1. Generate random input
    2. Copy/paste your solution and generate the output with your solution Now the error in your solution remained unnoticed, and unexpected and undocumented behaviour of your solution becomes requirements. But the solver will not notice until submitting...
  • smile67 Avatar

    Sometimes some testcases have rounding problems (see @donaldsebleung)... so in this case i mark it as an issue;-)!

  • donaldsebleung Avatar

    Good to see full test coverage including both fixed and random assertions but IMHO rounding isn't the best way to treat floating point values, especially how your reference solution rounds the values which causes my solution to disagree with yours (by 0.01) around 10% of the time. You may want to import the customised assertFuzzyEquals assertion method into your Preloaded section instead and use it in the test cases like any other assertion method:

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

    Note: if you do decide to use this assertion method (which I recommend), do not do any rounding in your reference solution whatsoever and remove the rounding instructions from the Description.