5 kyu
Randomize Objects
320 of 322surtich
Loading description...
Algorithms
Fundamentals
Arrays
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Hi. I got this error - "calling toRandomArray() and then try to get a given permutation of values After 100 attempts, has not obtained the desired permutation. Check the randomness of your solution." All tests pass except for this one. Could you tell me what is the test case fail?
This comment has been hidden.
The value types that need to be considered are
string
andnumber
. That should be stated in the description.As for the code, everything goes well if I am testing it outside of the kata. No problems with many nested levels, no problems with empty objects. However, I pass 6 tests from (?? 312 ??). I have no idea whether it is really expected I will write the tests. Is it? I haven’t checked other peoples’ solutions but I guess recursion is needed here, isn’t it? If so, the level of this kata is rather low!
I tested my code on node v0.10.35, and on my Firefox 36. No errors ocurred.
But this kata can't be solved.I'm new to Codewars.I can only see the Output just shows Incorrect!
I wonder if there's any error ocurred.Or I've misunderstood the kata's description ?
What I've implemented:
This comment has been hidden.
Are the test cases for this kata available for viewing? Being new to the site I just do not know where to look. Thanks!
No, the tests cases are not available for viewing. You have to solve the kata from the instructions. By sending the code, you'll see what you're failing.
I setup and tested the solution with Jasmine and the tests are passing. However, not when I sumbit the solution on the site.
Probably your solution has an error. When you submit the solution, what error message you see on the screen?
The "calling toRandomArray() and then try to get each value of the random array calling 100 times as much " case should add "checked = false" above the "while..."
This comment has been hidden.
This comment has been hidden.
Here is the output: Empty object tests Test Passed: Value == undefined Test Passed: Value == [] Object with one key tests obj.random() should return the only key - Expected: 1, instead got: undefined Test Passed: Value == [1] Object with one key multiple levels tests obj.random() should return the only key - Expected: 1, instead got: undefined Test Passed: Value == [1]
This comment has been hidden.
5 kyu seems a bit high for that one. 6 kyu maybe?
You talk about returning "keys", but it looks like you actually want values.
Fixed, thaks.
This needs better test cases.
There's no messages on the tests, and the tests are using
Test.expect(value, msg)
, which doesn't tell you anything about the values being tested. Instead, you should use one of the assert methods, likeTest.assertEquals(actual, expected, msg)
, and make sure you include a message as to what was tested.I also recommend grouping your tests into
describe()
andit()
blocks for better feedback.As it stands, this
isn't very solveableharder to solve than necessary, since I'm getting no feedback on the failures.Thanks for your suggestions.
I have refactored the tests grouping with
describe()
andit()
.However, most of the tests still using
Test.expect(value, msg)
. The reason is that what I do is to check that the methods actually generate random values and neither would be informative to useTest.assertEquals(actual, expected, msg)
. What I have done is add descriptive messages about what is wrong.I hope this helps!
The grouping helps a bunch, and the tests are much, much better. Thanks!
You could still use
assertEquals
in some places. For example, in "toRandomArray() tests", you could use it to assert the length (helpful because the user can see what the length of their array actually was without usingconsole.log()
.You also should add in which value was missing from the array into your message. That might be helpful.
Another option (which might not be better, so feel free to disregard this) would be to use
Test.assertSimilar(actualArray.sort(), expectedArray.sort(), "Sorted arrays were not equal")
.Thanks, again. You've helped me a lot!
I followed your first two advices. I think that is more informative than using
Test.assertSimilar(actualArray.sort(), expectedArray.sort(), "Sorted arrays were not equal")
.