6 kyu
Random Sequence Generator
143 of 144surtich
Loading description...
Algorithms
Fundamentals
Arrays
Games
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.
Poor tests - hard to solve step by step.
Author solution fails the tests (mutates instance attribute).
This comment has been hidden.
I think this is not really an issue. I think the check for randomity is ok.
Issue: describe your test cases, or at least add a default value.
You can add some suggestion for 'own test cases'. You can suggest a bit more about Randomizer.numbers: a shuffled array of min:max, next and sequence will return the first values and modify Randomizer.numbers.
Otherwise this is an interesting kata. I wanted to author a kata serie on pseudo random generator but missed an object structure/function. Would you mind if i use this kata as a basis for my serie ?
Hi Were_Cat!
I'd be happy that you use my kata as a base for your serie.
On the other hand, I have done the following:
I hope this is enough. Thanks for your help.
I removed the issue a sthere is no more problems.
I don't know what is the best practice for tests cases but here is what I do:
I seem to be failing this kata on a single test case, when sequence is called with an undefined size and no more numbers remaining (e.g., empty array of numbers). All I am getting for feedback is
Value is not what was expected
. What is the expected value in this case? I thought an empty array (array of size 0) would be the desired output, but it seems not. Should it be an error message? Should it benull
? Should it be something else entirely?I figured it out. The expectation is to throw an error when no more numbers remain and
sequence
is called (regardless ofsize
). This needs to be added to the description.You are right. Fixed it. Thanks!
I think the wording should be
An exception will be thrown if:
size
is greater than the number of numbers remainingsize
being passed or not)The specific error message is not important.
Also, here are a couple other points to address:
min
andmax
values passed to theRandomizer
constructor can be assumed to be valid (e.g., actual numbers,min <= max
) or if they need to be checked. With the current set of test cases, assuming valid inputs is safe.new Randommize(1,6)
instead ofnew Randomizer(1,6)
Thanks a lot, again. Really you are helping me. I have added all your suggestions.
Looks good. Before I mark the issue as resolved, there are two more things I noticed:
var r = new Randommizer(1,6);
should bevar r = new Randomizer(1,6);
sequence(size)
to be "...returns an array of length,size
, of random numbers. If nosize
is passed, returns the remaining random numbers." (i.e., change that first "size" to "length" and put ticks around the argument references) will help the readability.Did it! Thanks again!
Looks good, and I've marked the issue as resolved (and kata as ready)
Something weird has happened with me. I completed solution with one failed test. I haver never seen such behavior before. I guess the root cause is try()/catch() operators...
Strangely, one of the tests fails, but I still pass the kata. Not sure what that's about.
The error message was
Test Failed: Value is not what was expected
. I would have fixed the problem if there was something more to go on ;PIs this really expecting specific results? I get the error Test Failed: Expected: 8, instead got: 3 every time.
Now, I don't even know what the test covers, but it really looks like the test is expecting the first returned item to be an
8
, but my code returns one from the opposite end of the array, a3
.If you want to write a random-based test, you need to allow for random output.
Thanks for your feedback.
In the tests, I was replacing the
Math.random
method by another method that defines a fixed seed so I can control the sequence of random numbers.Now I realize that this strategy is wrong because maybe you are using a different formula that I use to generate the random numbers.
I changed the way to test the solution and I hope this time is correct.
Yes, that works much better. Thanks!