1   /*
2    *  Copyright 2006 Simon Raess
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.beep4j.internal.util;
17  
18  import junit.framework.TestCase;
19  
20  public class IntegerSequenceTest extends TestCase {
21  	
22  	public void testDefaultSequence() throws Exception {
23  		IntegerSequence sequence = new IntegerSequence();
24  		for (int i = 0; i < 50; i++) {
25  			assertEquals(i, sequence.next().intValue());
26  		}
27  	}
28  	
29  	public void testStartAt10() throws Exception {
30  		IntegerSequence sequence = new IntegerSequence(10, 1);
31  		for (int i = 10; i < 60; i++) {
32  			assertEquals(i, sequence.next().intValue());
33  		}
34  	}
35  	
36  	public void testIncrementBy2() throws Exception {
37  		IntegerSequence sequence = new IntegerSequence(1, 2);
38  		for (int i = 1; i < 20; i += 2) {
39  			assertEquals(i, sequence.next().intValue());
40  		}
41  	}
42  	
43  	public void testWrapAround() throws Exception {
44  		IntegerSequence sequence = new IntegerSequence(Integer.MAX_VALUE - 2, 1);
45  		assertEquals(Integer.MAX_VALUE - 2, sequence.next().intValue());
46  		assertEquals(Integer.MAX_VALUE - 1, sequence.next().intValue());
47  		assertEquals(Integer.MAX_VALUE - 0, sequence.next().intValue());
48  		assertEquals(0, sequence.next().intValue());
49  	}
50  	
51  }