Ad
  • Custom User Avatar

    Python: Random tests are vulnerable to input modification

  • Custom User Avatar

    python new test framework is required. updated in this fork

  • Custom User Avatar
  • Custom User Avatar
    • Python new test framework should be used (Refer this & this for more detail)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • Default User Avatar

    Hi, your compare-arrays function was rather... ugly, so here's a better one.

    Explanation: instead of 'if x return False else return True' simply 'return x'.
    Then I applied the DeMorgan law. (http://en.wikipedia.org/wiki/De_Morgan%27s_laws)

    def compare_arrays(a1, a2): return len(a1) == len(a2) && sorted(a1) == sorted(a2)

    EDIT: I think there is also no need for len(a1) == len(a2) by the way.
    Cheers.

  • Custom User Avatar

    No offence meant, but I am not exactly sure how this kata ever left the beta stage, but in the Python tests your should re-work the code for creating the random lists (it is rather easy, if I may say so), while the Ruby version of the Test Cases is probably better off with a total rewrite.

    Provided the author is still browsing CW or any admin/mod with enough power is interested, I can fix this kata in little time if asked :)

  • Custom User Avatar

    There seems to an issue with your solution (that random tests are compared to)

    First of all, you should explicitly say in the description whether you want duplicates in the return list or no.
    The issue is regarding the origin of those duplicates.

    For example, if a1 = [28, 23, 39, 32, 22, 14, 25, 39, 41, 18, 34, 34, 4, 42, 48, 38, 3, 47, 28, 25, 7, 42, 43, 17]; a2 = [17]; a3 = [16, 31, 40, 40, 13](40 is present twice in the a3), the solution out = [[23, 17, 40], [14, 17, 31]] is marked as incorrect. One would assume that duplicates should then be included in the return list (which most of the if sum in a3 lack).

    This is confirmed by the fact that if a1 = [30, 43, 21, 26, 22]; a2 = [2, 15, 4]; a3 = [41, 34, 41, 27, 12] (41 is present twice in the a3), the solution out = [[30, 4, 34], [26, 15, 41], [26, 15, 41]] is marked as correct.

    However, if a1 = [34,35,34]; a2 = [49,29,49,47,20,22,29,34,8,2,44,39,0,14,43,21,28]; a3 = [18,42,12,2,0,13] (34 is present twice in the a1), the seemingly correct solution out = [[34, 8, 42], [34, 8, 42]] is marked as incorrect. One would assume that duplicates should then be omitted from the return list. The same happens if there is a duplicate in a2.

    This leads to a conclusion that a1 and a2 need to be set'ed, while a3 — not. Please state that in the description or change or own solution.

    On a side note, I think you should increase the length (or decrease the spread) of random arrays, as most of the time the correct solution is simply an empty array.

    (All of the above examples were taken from the output console directly. Seems weird that no one noticed this in the time this kata has been around.)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution