Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Python: Random tests are vulnerable to input modification
python new test framework is required. updated in this fork
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)
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.
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 :)
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 thea3
), the solutionout = [[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 theif 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 thea3
), the solutionout = [[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 thea1
), the seemingly correct solutionout = [[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 ina2
.This leads to a conclusion that
a1
anda2
need to beset
'ed, whilea3
— 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.)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution