7 kyu

Student Rankings

Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • Kaham Avatar

    For some random tests, the expected length seems to be off by one?

    ['94366 - KzQgybHa - 51.7 43.2 56.2 36.9 46.0', '61746 - jnsGvIel - 53.4 59.2 14.0 34.4', '96362 - EDFTyzLS - 43.6 58.3 85.5', '34877 - yVLBMuTK - 59.0 25.0 60.1', '28164 - xtHvMYWi - 18.3 69.6 98.4 34.8', '29873 - DopOhJfi - 18.2 76.4 29.1 10.2', '67638 - nOXGIqOs - 55.0 89.0 82.6', '58755 - IlLRxYYZ - 94.6 79.2 40.5', '67638 - IETAxXyI - 13.1 83.4 73.2 87.4 13.3']

    The attempt length (9) does not equal the answer length (8)

    Yet, I'm pretty sure that the list has 9 inputs?

  • hobovsky Avatar

    Colored text is difficult to read in light mode.

  • tigerk00 Avatar

    Great Kata! Hope to see it in approved

  • Blind4Basics Avatar

    Hi again, :)

    ['81397 - hYoXxlqv - 21.7 15.2 56.2', '74957 - dHEWuIaR - 46.9 67.3 69.0 28.6 79.3', '97826 - DZacwyKZ - 14.9 60.6 50.1 29.1 92.1', '06161 - woMAdLll - 43.2 42.8 65.1 50.9 12.1', '52356 - EgPpavhp - 37.3 56.5 91.4 27.2 45.4', '70243 - rXSpunhu - 16.5 26.6 32.4', '99165 - lcBconSj - 65.2 20.1 87.7 72.9 11.9']
    Checking correct id:
    Test Passed
    Log
    Checking correct value:
    Test Passed
    Log
    Checking correct id:
    '52356' should equal '99165'
    Log
    Checking correct value:
    Test Passed
    Log
    Checking correct id:
    '99165' should equal '52356'
    

    ok, so:

    • first: you shouldn't log the tests like that to the console.
    • second: Espicially, if you have several assertions for one single input, you should group those tests inside the same test.it block (note: you can nest describe blocks if needed but you have to have one single layer of it blocks as "leaves")
    • lastly: it seams, according to the above failed test, that you have a secondary key for sorting that isn't specified in the description => this should be specified in the description. For now, the description requires that in case of equality of the mean, the students are kept in order of the original list, but you're sorting them by id instead (edit: mmh, no seems it's somethign else)

    Cheers

    • tjf952 Avatar

      I will look into it thankyou, you are very fast w(°o°)w

    • Blind4Basics Avatar

      if I'm not mistaken, it's because you use reverse

    • dfhwze Avatar

      No secondary key required

    • Blind4Basics Avatar

      secondary key required. ;p look at my solution, you'll see the nuance

      (if I'm mistaken thre, that would mean the problem comes from the float thing in my solution... That would be surprising)

    • dfhwze Avatar

      Check my fork on your solution. Or am I missing something here?

    • Blind4Basics Avatar

      am I missing something here?

      yup ;) See next fork with the case as fixed test

    • Blind4Basics Avatar

      wait, there's another problem, apparently... My code with his "sorting way" seems to no pass... Investigating...

    • Blind4Basics Avatar

      holy fuck... x(

      mine: [('74957', 58.22), ('52356', 51.56), ('99165', 51.56), ('97826', 49.36), ('06161', 42.82), ('81397', 31.033333333333335), ('70243', 25.166666666666668)]
      his:  [('74957', 58.21999999999999), ('99165', 51.56), ('52356', 51.55999999999999), ('97826', 49.36), ('06161', 42.82), ('81397', 31.03333333333333), ('70243', 25.166666666666668)]
      

      the problem doesn't come from the sorting but from the float computation......... Pretty weird considering what we use.... :/

    • Blind4Basics Avatar

      @jf952: ok, it seems it's because I use the module while you use... "bare computation", let's say. That's pretty weird, but... nothing related to sorting (I was actually wrong about that, apprently... I'd need a refresh about this detail, maybe).

      I see only one way out of this: you try your random inputs and check there are no two students that can be considered "equal". If that's the case you generate another array instead of doing the test

    • dfhwze Avatar

      If ordering depends on floating point numbers, perhaps this kata requires exact floating point numbers (Fraction) instead? For the moment, this kata remains ill-defined because of the disprepancy we just found.

    • Blind4Basics Avatar

      yeah, that's another way. But there you find the need for the secondary key again, I believe.

    • dfhwze Avatar

      Your proposed solution of "unique" scores seems the easier way out of this, without changing the spirit of the kata :)

    • tjf952 Avatar

      So I ran some tests, and it seems that there isn't secondary sorting based on id:

      Test Case: ['B000 - Bruce Wayne - 100', 'A000 - Alfred Pennyworth - 100', 'K000 - Kate Kane - 100']
      Attempt: [('B000', 100.0), ('A000', 100.0), ('K000', 100.0)]  | Desired Answer: [('A000', 100), ('B000', 100), ('K000', 100)]
      
      Test Case: ['100 - AaBb - 100', '990 - CcDd - 100', '555 - EeFf - 100', '90 - GgHh - 100', '9354 - IiJj - 100']
      Attempt: [('100', 100.0), ('990', 100.0), ('555', 100.0), ('90', 100.0), ('9354', 100.0)]  | Desired Answer: [('100', 100), ('555', 100), ('90', 100), ('9345', 100), ('990', 100)]
      

      If you want, I can add secondary sorting. As it is now, my solution (the attempt above) only sorts based on grade and keeps it in the same order rather than sorting based on alphanumerical characters in the id.

      As for the other notes you left, I believe I implemented them (I learned more stuff on test cases!).

      EDIT: I should have refreshed before submitting... whoops >u<

    • dfhwze Avatar
      @test.it('Random Test Case '+str(i))

      Not sure how relevant "i" is. Perhaps you can display "students" in the "it".

    • dfhwze Avatar

      Also about the ordering, the problem is you get 58.21999999999999 while we get 58.22. If 2 students have silimar scores like this, your order might be student 1 -> student 2, while ours is student 2 -> student 1. A secondary key won't change this. The problem is how the mean gets calculated differs between your solution and ours, it's not clearly specififed how to get the mean, and the chosen implementation changes the outcome.

    • tjf952 Avatar

      Okay I believe I followed the proposed solution of "unique" scores by comparing the values formatted to one decimal points, if there are same values I create a new list for testing, else I continue. As for the i, I had it just for my logging purposes, so I removed it. Let me know if this satisfies the criteria that was originally posted.

    • dfhwze Avatar

      I would still consider changing this:

      Random Test Case
      
      Log
      ['59306 - NlfzEhom - 68.9 92.8 22.8 97.0', '01815 - hJTbdHZK - 00.7 14.3 32.1 98.0 48.3', '61722 - VhFNAGqW - 64.5 24.6 49.5 89.9 93.4', '83273 - fNGmMGKm - 98.9 00.1 96.9 23.3 44.6', '27520 - MUgMUYio - 43.0 15.0 05.1']
      

      Remove the log, and add the message you are logging in the "it", so it's part of the test case.

    • tjf952 Avatar

      got it

      Issue marked resolved by tjf952 4 years ago
    • dfhwze Avatar

      looks good to me

  • rge123 Avatar
  • Blind4Basics Avatar

    Use custom comparator with assert_approx_equals instead of rounding float values.

    now:

    59.52 should be close to 59.53 with absolute or relative margin of 1e-09
    

    dolamroth didn't say use assert_approx_equals AND rounding. This is even worse than it was before.

    => remove the rounding requirement.

  • dolamroth Avatar

    (=✖ ᆺ ✖=)

    Having multiple output types is bad.

    • tjf952 Avatar

      Do you mean a (string, float) is bad?

    • dolamroth Avatar

      Now the return type is either List[Tuple[str, float]], or None. It is not a good practice, since in real code you may expect, that other code using your function may always expect a list and not handle a corner case with None.

      Of course, you may say that kata is not real world code, but it rather falls into an unnecessary work for user. Note, that in mine of FArekkusu's solution None is just returned as sorted(...) or None.

      It would be preferrable, if List[Tuple[str, float]] was always expected as output.

    • Chrono79 Avatar

      An empty list for an empty list as input could work tho.

    • tjf952 Avatar

      Fixed 。◕ ‿ ◕。

      Issue marked resolved by tjf952 4 years ago
  • dolamroth Avatar

    /ᐠ。ꞈ。ᐟ\

    Use custom comparator with assert_approx_equals instead of rounding float values. How to https://docs.codewars.com/authoring/kata/floating-point/#what-are-floating-point-numbers