Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing for stochastic processes?

Is there a sane way to unit test a stochastic process? For example say that you have coded a simulator for a specific system model. The simulator works randomly based on the seeds of the rngs so the state of the system cannot be predicted and if it can be every test should bring the system to a specific state before it attempts to test any method of a class. Is there a better way to do this?

like image 340
imoschak Avatar asked Jul 25 '10 10:07

imoschak


People also ask

What is stochastic testing?

In these cases, a stochastic testing is used where the original test data are determined by a multitude of random variables with respective distributions, and in order to compare the results obtained it is common to use the distributions of random variables.

What is retrofit testing?

Retrofit - probably the most popular networking client in Android development. Basically it allows to create HTTP client in an interface - you just add annotation with HTTP method, relative or absolute path and proper request is constructed.


2 Answers

The two obvious choices are to remove the randomness (that is, use a fixed, known seed for your unit tests and proceed from there), or to test statistically (that is, run the same test case a million times and verify that the mean and variance (etc.) match expectations). The latter is probably a better test of your system, but you'll have to live with some false alarms.

like image 99
Drew Hall Avatar answered Sep 21 '22 16:09

Drew Hall


Here's a nice blog post that covers this topic. Basically you will need to inject a controlled randomness into the object under test.

like image 40
Darin Dimitrov Avatar answered Sep 21 '22 16:09

Darin Dimitrov