0

Let's say I have a random number generator for 3 categories:

Prob Yield
0.1 10
0.2 5
0.7 2

The expected yield is 1 + 1 + 1.4 = 3.4

Currently I have something like this

sum = 0
N = 10000
for i in 1 to N:
    sum += getYeild()
assert(sum / N - 3.14 < some threshold)

So what is the best criterion I can use for this unit test to make an assertion?

zs2020
  • 53,766
  • 29
  • 154
  • 219
  • You can't legitimately test distributional behavior based on just the expected value. For instance, `[(0.1, 0), (0.2, 10), (0.7, 2)]` also has an expected yield of 3.4. (Even if you wanted to base a test on the mean, you should be using `absolute value < threshold` because the observed outcome can fall to either side of the mean.) I'd recommend that you check out the [Chi-square test](https://en.wikipedia.org/wiki/Chi-squared_test). – pjs Jan 01 '21 at 16:46
  • With statistical tests and randomness, you'll also need to specify some degree of risk tolerance, i.e., how tolerant are you to false negatives and false positives. That would determine how large a sample size you'll need for your test. – pjs Jan 01 '21 at 16:47

0 Answers0