Solved

To test a random return value function.

Posted on 2011-09-20
5
175 Views
Last Modified: 2012-06-27
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
Comment
Question by:sriramvemaraju2000
  • 3
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36571274
0
 
LVL 47

Expert Comment

by:for_yan
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

by:sriramvemaraju2000
ID: 36571336
Thanks for your help.
0
 
LVL 47

Expert Comment

by:for_yan
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

by:
reijnemans earned 500 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);
		randomResults.add(randomResult);
	}
	
	
	public Integer random () {
		Double r1 = Math.random();
		Double r2 = r1 * 100; 
		return r2.intValue();
	}

Open in new window


pay attention add the @Test
 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question