Ad
  • Custom User Avatar

    "Calculate a math formula" is not a novel idea.

  • Custom User Avatar

    Returning time compotent is pointless.

  • Custom User Avatar

    Yup:

    • Fixed the values in the description supplying output with rounding to first decimal place instead. The tests accept both rounded and unrounded inputs.
    • Decided to leave only one hardcoded sample test for 100 with the rest being randomly generated via a for loop. There're 10 of these now.
    • Dropped the reference to 0 value.
  • Custom User Avatar

    This is looking good. :]

    Couple things you missed:

    • The Description example still has truncated values in it.
    • dist===0 is not a special case (this is why I wanted [[0,0]] instead of [0,0] :). you can remove that line from your example and reference solution.
    • the hardcoded expected values have some x.09999999999999 values in them. that should really be x.1; you're seeing JavaScript floating point inaccuracy in action. assertApproxEquals is taking care of that though.
    • you could of course wrap all the repetitive tests in a for loop. get hardcoded values from a hardcoded array, indexed with the loop. that also makes it easier to have some more random tests. it's not essential, but 50 or a 100 won't hurt. (if ever you find an edge case with a random test, make it into a fixed test!)
  • Custom User Avatar

    Okay, I think I finally managed to wrap my head around this, random test cases and all. Please have a look if I missed/misunderstood anything. Again, thanks for helping out.

  • Custom User Avatar

    When working with floating point values, there should be no rounding. That's the whole point of assertApproxEquals.

    So expected[1][0] should now be 6.1 instead of 6.

    Also, you now have only one test. A bit of copy/pasting to have some more would be nice. I especially wrote it so you only have to change arg and expected in one place.

  • Custom User Avatar

    Well, I just pasted it in and it seems to be working. I'll try to figure out random test cases in a day or two. Thanks for your feedback and input!

  • Custom User Avatar

    Does this help?

    { const arg = 11;
      Test.it(`Dropping the ball from ${arg} meters`, ()=>{
        const expected = [ [11,0], [6,1], [0,2] ]; // or a function output. need that for random tests anyway
        const actual = gravity(arg);
        Test.assertEquals( actual.length, expected.length, "Incorrect fall time:" );
        actual.forEach( ([h,t],i) => {
          Test.assertApproxEquals( h, expected[i][0], `Height error at ${i} seconds:` );
          Test.assertEquals( t, expected[i][1], `Time error at ${i} seconds:` );
        } );
      });
    }
    

    I haven't tested it, this is just straight head | keyboard > code.

  • Custom User Avatar

    That's exactly what I wanted to suggest ;)

  • Custom User Avatar

    I'm a little shaky on testing and it seems that implementing Test.assertApproxEquals will require overhauling the tests altogether because of the comparison I use. I'll try to figure it out, but, if you feel up to it, contributions are more than welcome ;-)

    I'll change the output for 0 (done). Thanks.

  • Custom User Avatar

    Rounding errors in the reference solution cause my valid solution to fail:

    Expected:    '[[3240,0],[3235,1],[3220,2],[3195,3],[3161,4],[3117,5],[3063,6],[2999,7],[2926,8],[2843,9],[2750,10],[2647,11],[2534,12],[2411,13],[2279,14],[2137,15],[1985,16],[1823,17],[1652,18],[1471,19],[1279,20],[1079,21],[868,22],[647,23],[417,24],[177,25],[0,26]]',
    instead got: '[[3240,0],[3235,1],[3220,2],[3195,3],[3161,4],[3117,5],[3063,6],[2999,7],[2926,8],[2843,9],[2750,10],[2647,11],[2534,12],[2411,13],[2279,14],[2137,15],[1985,16],[1823,17],[1652,18],[1471,19],[1280,20],[1079,21],[868,22],[647,23],[417,24],[177,25],[0,26]]'
    

    [1280,20] really is correct! (Use Test.assertApproxEquals instead of rounding.)

    No random tests.

    Inconsistent return type: gravity(0) should return [[0,0]].

  • Custom User Avatar

    Yeah, I didn't check around for similar kata, just wanted to try and publish my own. Because reasons. Guess I'll un-publish it in a few days.

  • Custom User Avatar
  • Custom User Avatar

    Sorry about that. All fixed now. Thanks for pointing this out.

  • Custom User Avatar

    "fourty" ?!?

    Better specify the numbers if you're going to use alternative spellings.