aefc21856877a574ec926c53b44fbacc5c5ebb7b
[debian/openrocket] / core / test / net / sf / openrocket / util / ArrayUtilsTest.java
1 package net.sf.openrocket.util;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5
6 import org.junit.Test;
7
8 public class ArrayUtilsTest {
9
10         @Test(expected=NullPointerException.class)
11         public void testCopyOfRange_NullArg() {
12                 ArrayUtils.copyOfRange( (Byte[]) null, 0 , 14);
13         }
14         
15         @Test(expected=ArrayIndexOutOfBoundsException.class)
16         public void testCopyOfRange_StartTooBig() {
17                 Integer[] original = new Integer[5];
18                 ArrayUtils.copyOfRange( original, 8 , 14);
19         }
20         
21         @Test(expected=ArrayIndexOutOfBoundsException.class)
22         public void testCopyOfRange_StartTooSmall() {
23                 Integer[] original = new Integer[5];
24                 ArrayUtils.copyOfRange( original, -1 , 14);
25         }
26         
27         @Test(expected=IllegalArgumentException.class)
28         public void testCopyOfRange_IllegalRange() {
29                 Integer[] original = new Integer[5];
30                 ArrayUtils.copyOfRange( original, 5, 0 );
31         }
32         
33         @Test
34         public void testCopyOfRange() {
35                 Integer[] original = new Integer[5];
36                 for ( int i =0; i < 5; i++ ) {
37                         original[i] = i;
38                 }
39                 Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
40                 assertEquals( 0, copy.length );
41                 
42                 copy = ArrayUtils.copyOfRange( original, 2, 2 );
43                 assertEquals( 0, copy.length );
44                 
45                 copy = ArrayUtils.copyOfRange( original, 0, 2 );
46                 assertEquals( 2, copy.length );
47                 for( int i =0; i< 2; i++ ) {
48                         assertEquals( original[i], copy[i] );
49                 }
50
51                 copy = ArrayUtils.copyOfRange( original, 2, 5 );
52                 assertEquals( 3, copy.length );
53                 for( int i =0; i< 3; i++ ) {
54                         assertEquals( original[i+2], copy[i] );
55                 }
56
57                 copy = ArrayUtils.copyOfRange( original, 2, 15 );
58                 assertEquals( 13, copy.length );
59                 for( int i =0; i< 3; i++ ) {
60                         assertEquals( original[i+2], copy[i] );
61                 }
62                 for ( int i=3; i< 13; i++ ) {
63                         assertNull(copy[i]);
64                 }
65
66         }
67
68         @Test
69         public void testCopyOfRange_ZeroSize() {
70                 Integer[] original = new Integer[0];
71
72                 Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
73                 assertEquals( 0, copy.length );
74                 
75                 copy = ArrayUtils.copyOfRange( original, 0, 2 );
76                 assertEquals( 2, copy.length );
77                 for( int i =0; i< 2; i++ ) {
78                         assertEquals( null, copy[i] );
79                 }
80
81         }
82         
83
84 }