Solved

To test a random return value function.

Posted on 2011-09-20
5
176 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
[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
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 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