Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

A random seed that makes tests fail the same way every time?

I’ve never worked with the random library and I’m a bit confused about what this fixme statement is asking me to do. Is there a seed number that specifically does this?

The code is making an ordered list ADT and this file is testing the functions within that file. We use the random library to create random numbers that will be added into, or removed from the ordered list ADT.

Please let me know if there’s any other information I should give!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

enter image description here

>Solution :

When you set the seed, as is done here, you should get a consistent set of random numbers afterwards.

If the numbers that you’re getting are NOT consistent, then one of the following is true:

  1. You’re using a different random number function somewhere so setting the seed didn’t fix it.
  2. The test depends on external state, so it does different things on different runs.
  3. You’re trying to compare running the entire test suite to testing a single function.

The right fix will depend on which of those is the issue.

  1. Find where you’re using a different generator and either stop, or mock it out.
  2. Find the external state and set it or mock it out.
  3. Move setting the seed into a setUp method so that it is set fresh for every test.

My guess is that your problem is the last. But if it isn’t, hopefully this answer gives you somewhere to start digging from.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading