0

Using Scala, I've a method that return a set of 5 random numbers, that should be between 1 and a constant LIMIT.

What's the best approach to test that a answer will never return more/less than 5 elements, and all elements are between 1 and LIMIT? Making a simple test is easy. But should I make a loop of, lets say, 1000 iterations to better test it? Or there is some feature in unit testing for such cases?

Using Scala and ScalaTest.FunSuite

pedrorijo91
  • 7,635
  • 9
  • 44
  • 82

2 Answers2

2

Take a look at https://softwareengineering.stackexchange.com/questions/147134/how-should-i-test-randomness

My approach would be to generate 100 sets for the limit 20 and test if the occurrences of each number are nearly equally divided.

Community
  • 1
  • 1
Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43
2

Let's try QuickTheories - property based testing framework. It runs tests with many different possible generated input.

Marcin
  • 137
  • 1
  • 5
  • 2
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bhargav Rao Mar 14 '16 at 20:53