[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

To test a random return value function.

Posted on 2011-09-20
5
Medium Priority
?
180 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 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);
		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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.
Suggested Courses

649 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