Tagged ensure4j

Statistical Unit Tests with ensure4j

As part of another project I am developing ensure4j. The syntax (see the examples here) is working quite nicely, ensure4j is already very useful for internal use.

Lately I was busy adding tests that are able to verify if some code (e.g. an optimizer that uses random, like genetic algorithm, simulated annealing, …) produces the desired in e.g. 95% of the cases (Wikipedia has a nice practical example for confidence intervals).

Example Usage

Here is an example that tests the nonsense code Math.random() * 2.
[sourcecode language=”java”]ensure(new Experiment() {
public double measure() {
return Math.random() * 2;
}).between(0.9, 1.1, 0.95).sample(10, 100);[/sourcecode]

The code most likely does not make much sense out of context like this, so here is an explanation of what it does:

Read more