1 package net.sf.openrocket.util;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
8 public class ArrayUtilsTest {
10 @Test(expected=NullPointerException.class)
11 public void testCopyOfRange_NullArg() {
12 ArrayUtils.copyOfRange( (Byte[]) null, 0 , 14);
15 @Test(expected=ArrayIndexOutOfBoundsException.class)
16 public void testCopyOfRange_StartTooBig() {
17 Integer[] original = new Integer[5];
18 ArrayUtils.copyOfRange( original, 8 , 14);
21 @Test(expected=ArrayIndexOutOfBoundsException.class)
22 public void testCopyOfRange_StartTooSmall() {
23 Integer[] original = new Integer[5];
24 ArrayUtils.copyOfRange( original, -1 , 14);
27 @Test(expected=IllegalArgumentException.class)
28 public void testCopyOfRange_IllegalRange() {
29 Integer[] original = new Integer[5];
30 ArrayUtils.copyOfRange( original, 5, 0 );
34 public void testCopyOfRange() {
35 Integer[] original = new Integer[5];
36 for ( int i =0; i < 5; i++ ) {
39 Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
40 assertEquals( 0, copy.length );
42 copy = ArrayUtils.copyOfRange( original, 2, 2 );
43 assertEquals( 0, copy.length );
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] );
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] );
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] );
62 for ( int i=3; i< 13; i++ ) {
69 public void testCopyOfRange_ZeroSize() {
70 Integer[] original = new Integer[0];
72 Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
73 assertEquals( 0, copy.length );
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] );