Solved

To test a random return value function.

Posted on 2011-09-20
5
172 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
Comment Utility
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility

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
Comment Utility
Thanks for your help.
0
 
LVL 47

Expert Comment

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
array220 challenge 8 45
json example 39 110
Java / Linux and Regular Expressions 11 43
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now