Sunday, 15 May 2011

java - Testing for Randomness in JUnit Framework -



java - Testing for Randomness in JUnit Framework -

i'm working on training myself in stiff test driven development junit atmosphere. i'm trying find out best method testing randomness in such atmosphere. example, i'm working on implementing randomized queue array queues , item , switches item item index 0-(n-1) on array (thus simulating random item coming off queue when dequeued). here's illustration code form enqueue method:

int randindex = stdrandom.uniform(size); // generate random index swap lastly item item tmp = randarray[randindex]; randarray[size] = item; randarray[randindex] = randarray[size]; //perform swap create random item dequeue randarray[size] = tmp; size++;

i want run few tests create sure enqueue method randomly switching queued variable other index in array. i'd throw code in main() method iterates through bunch of enqueue() calls , prints results, i'd check create sure "felt" random.

but, said, want in stiff unit testing framework. seems junit pretty much exclusively uses assert statements, i'm not sure should assert against what, unless run monte carlo type thing , check average against epsilon, seems little much testing such simple method.

you can split test in 2 parts.

1) test given sequecne of pseudo random numbers, queing works expected. define arbitray fixed number of int values: e.g "5,2,100,3". test asser enque, deque delivers expected element.

2) test random() class of java: you, should omit test, because random() implemented.

otherwise 2) have using chi-square random number test, , that thi sstatistic within soem epsilon stated. woul dbe overkill, remain point 1)

java junit

No comments:

Post a Comment