Testing methods that return a range of results
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, February 25, 2003 10:40 AM


Is there any easy way to test with JUnit a method that returns a range of values like, for instance, in a method that rolls a die and the result has to be between 1 and 6?

Re: Testing methods that return a range of results

Posted By:   David_Bates  
Posted On:   Saturday, March 1, 2003 03:16 PM

I think the sort of thing you'd end up with is something like this:

private Dice myDice;

public void setup() {
myDice = new Dice();
}

public void testDiceThrow() {
int lowest = 1;
int highest = 6;
int result;

result = myDice.throw(1, 6);
assertTrue(result >= lowest && result <= highest);
}

(I did this without looking at the API, so excuse me if I get some of the names wrong).



I know the example isn't perfect but I think you'll get the point.

Re: Testing methods that return a range of results

Posted By:   Anonymous  
Posted On:   Wednesday, February 26, 2003 05:55 AM

What exactly do you want to test? That the value is in the specified range, or something more specific?
About | Sitemap | Contact