6 kyu

Random Sequence Generator

143 of 144surtich
Description
Loading description...
Algorithms
Fundamentals
Arrays
Games
  • Please sign in or sign up to leave a comment.
  • gkucmierz Avatar

    Poor tests - hard to solve step by step.

  • Voile Avatar

    Author solution fails the tests (mutates instance attribute).

  • Freywar Avatar

    This comment has been hidden.

  • user3482173 Avatar

    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 ?

    • surtich Avatar

      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:

      • The validation tests are now available during the kata completion.
      • I have clarified using your words what the function Randomizer does.

      I hope this is enough. Thanks for your help.

    • user3482173 Avatar

      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:

      • For the kata test cases: I think the user should know what you test whitout having access to tests code. The best way to do this is to use the framework. You can describe your test and return messages to explain what is wrong:
      describe('Simple tests', function() {
        it('should handle basic values', function() {
          Test.assertSimilar(factorise1(10), [2,5], 'Input of 10');
          //...
        });
        // Add more simple tests here
      });
      
      // Add more descibe blocks, such as one for "Error handling"
      
      • For the kata test suggestion I only use very few simple test (one or two by function to test). I think suggestions should only test for general behavior.
  • mlabrum Avatar

    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 be null? Should it be something else entirely?

    • mlabrum Avatar

      I figured it out. The expectation is to throw an error when no more numbers remain and sequence is called (regardless of size). This needs to be added to the description.

    • surtich Avatar

      You are right. Fixed it. Thanks!

    • mlabrum Avatar

      I think the wording should be


      An exception will be thrown if:

      • Call next() and no more numbers remain
      • Call sequence(size) and size is greater than the number of numbers remaining
      • Call sequence(size) and no more numbers remain (regardless of size being passed or not)

      The specific error message is not important.


      Also, here are a couple other points to address:

      • I suggest explicitly stating if the min and max values passed to the Randomizer 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.
      • There's a typo in the example: new Randommize(1,6) instead of new Randomizer(1,6)
    • surtich Avatar

      Thanks a lot, again. Really you are helping me. I have added all your suggestions.

    • mlabrum Avatar

      Looks good. Before I mark the issue as resolved, there are two more things I noticed:

      • The example still has the extra 'm' in the constructor name: var r = new Randommizer(1,6); should be var r = new Randomizer(1,6);
      • I think rewording the description of sequence(size) to be "...returns an array of length, size, of random numbers. If no size 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.
    • surtich Avatar

      Did it! Thanks again!

    • mlabrum Avatar

      Looks good, and I've marked the issue as resolved (and kata as ready)

      Issue marked resolved by mlabrum 11 years ago
  • kesheshyan Avatar

    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...

  • wthit56 Avatar

    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 ;P

  • OverZealous Avatar

    Is 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, a 3.

    If you want to write a random-based test, you need to allow for random output.

    • surtich Avatar

      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.

    • OverZealous Avatar

      Yes, that works much better. Thanks!