-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleIteratorTest.java
More file actions
executable file
·49 lines (45 loc) · 1.28 KB
/
SimpleIteratorTest.java
File metadata and controls
executable file
·49 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.ArrayList;
import java.util.Random;
/**
* SimpleIterator reviews the basic behavior of an iterator.
*
* @author ace
* @version 11 April 2010
*/
public class SimpleIteratorTest
{
private ArrayList<Thing> things;
int nThings;
Random rnd;
/**
* Constructor for objects of class SimpleIteratorTest
*/
public SimpleIteratorTest(){
rnd = new Random();
things = new ArrayList<Thing>();
}
/**
* Thing has a space for a number. Number the things by 5's,
* starting at 5.
*/
public void testNumber(){
fillThings();
ThingNumberer tn = new ThingNumberer();
ArrayList<Thing> numberedThings = tn.numberThings(things);
int index = rnd.nextInt(nThings);
if(numberedThings.size()==things.size()
&& numberedThings.get(index).getNumber()==((index + 1)*5)){
System.out.println("testNumber passes!");
} else {
System.out.println("testNumber fails");
}
}
private void fillThings(){
int index = 0;
nThings = rnd.nextInt(100) + 1; //ensures that there will always be at least one Thing
while(index <= nThings){
things.add(new Thing());
index++;
}
}
}