Solved

# To test a random return value function.

Posted on 2011-09-20
Medium Priority
178 Views
I want to unit test a function which is returning a random value from an array-list . I want to check whether the function is returning a random value or not .
0
Question by:sriramvemaraju2000
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 47

Expert Comment

ID: 36571274
0

LVL 47

Expert Comment

ID: 36571294

these are some useful  discussions on this subject and even applet , but no code is provided
http://sprng.fsu.edu/Version2.0/test-suite.html
0

Author Comment

ID: 36571336
0

LVL 47

Expert Comment

ID: 36571346
You are welcome.
For some reason I cannot find any java source code for testing of random generator;
I'm sure it  should be avaialable

This is code in C:

http://www.fourmilab.ch/random/random.zip

0

LVL 4

Accepted Solution

reijnemans earned 2000 total points
ID: 36571966
Hi,

TestNG gives some features that may be usefull for testing the random generator:

``````	private static List<Integer> randomResults = new ArrayList<Integer>();

@Test(invocationCount=100, successPercentage=50)
public void TestRandom() {
Integer randomResult = random();
if (randomResults.contains(randomResult)) {
Assert.fail("result is returned before " + randomResult);
}
System.out.println(randomResult);
}

public Integer random () {
Double r1 = Math.random();
Double r2 = r1 * 100;
return r2.intValue();
}
``````

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.
###### Suggested Courses
Course of the Month9 days, 14 hours left to enroll