1 package de.bwaldvogel.liblinear;
2
3 import static org.fest.assertions.Assertions.assertThat;
4 import static org.fest.assertions.Fail.fail;
5
6 import org.junit.Test;
7
8
9 public class ArrayPointerTest {
10
11 @Test
12 public void testGetIntArrayPointer() {
13 int[] foo = new int[] {1, 2, 3, 4, 6};
14 IntArrayPointer pFoo = new IntArrayPointer(foo, 2);
15 assertThat(pFoo.get(0)).isEqualTo(3);
16 assertThat(pFoo.get(1)).isEqualTo(4);
17 assertThat(pFoo.get(2)).isEqualTo(6);
18 try {
19 pFoo.get(3);
20 fail("ArrayIndexOutOfBoundsException expected");
21 } catch (ArrayIndexOutOfBoundsException e) {}
22 }
23
24 @Test
25 public void testSetIntArrayPointer() {
26 int[] foo = new int[] {1, 2, 3, 4, 6};
27 IntArrayPointer pFoo = new IntArrayPointer(foo, 2);
28 pFoo.set(2, 5);
29 assertThat(foo).isEqualTo(new int[] {1, 2, 3, 4, 5});
30 try {
31 pFoo.set(3, 0);
32 fail("ArrayIndexOutOfBoundsException expected");
33 } catch (ArrayIndexOutOfBoundsException e) {}
34 }
35
36 @Test
37 public void testGetDoubleArrayPointer() {
38 double[] foo = new double[] {1, 2, 3, 4, 6};
39 DoubleArrayPointer pFoo = new DoubleArrayPointer(foo, 2);
40 assertThat(pFoo.get(0)).isEqualTo(3);
41 assertThat(pFoo.get(1)).isEqualTo(4);
42 assertThat(pFoo.get(2)).isEqualTo(6);
43 try {
44 pFoo.get(3);
45 fail("ArrayIndexOutOfBoundsException expected");
46 } catch (ArrayIndexOutOfBoundsException e) {}
47 }
48
49 @Test
50 public void testSetDoubleArrayPointer() {
51 double[] foo = new double[] {1, 2, 3, 4, 6};
52 DoubleArrayPointer pFoo = new DoubleArrayPointer(foo, 2);
53 pFoo.set(2, 5);
54 assertThat(foo).isEqualTo(new double[] {1, 2, 3, 4, 5});
55 try {
56 pFoo.set(3, 0);
57 fail("ArrayIndexOutOfBoundsException expected");
58 } catch (ArrayIndexOutOfBoundsException e) {}
59 }
60 }