View Javadoc
1   /*
2    * Copyright 2010 Ange Optimization ApS
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 eu.simuline.octave.type;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotSame;
20  import static org.junit.Assert.assertTrue;
21  
22  import org.junit.Ignore;
23  import org.junit.Test;
24  
25  
26  /**
27   * Test {@link OctaveLong}
28   */
29  public class TestOctaveLong {
30  
31      /**
32       * Test equals
33       */
34      @Test public void testEquals() {
35          final OctaveLong s1a = longScalar(1);
36          final OctaveLong s1b = longScalar(1);
37          final OctaveLong s1c = longScalar(0);
38          s1c.set(1, 1, 1);
39  
40          assertEquals(s1a, s1b);
41          assertEquals(s1a, s1c);
42          assertEquals(s1b, s1c);
43          assertNotSame(s1a, s1b);
44          assertNotSame(s1a, s1c);
45          assertNotSame(s1b, s1c);
46  
47          final OctaveLong s0 = longScalar(0);
48          final OctaveLong s2 = longScalar(2);
49  
50          assertTrue(!s1a.equals(s0));
51          assertTrue(!s1a.equals(s2));
52      }
53  
54      private static OctaveLong longScalar(final long i) {
55          return new OctaveLong(new long[] { i }, 1, 1);
56      }
57  
58      /**
59       * Simple test of set and get
60       */
61      @Test public void testGetAndSet() {
62          final OctaveLong matrix = new OctaveLong(3, 6, 5, 4);
63          assertEquals(0, matrix.get(2, 5, 2, 3));
64          matrix.set(42, 2, 5, 2, 3);
65          assertEquals(42, matrix.get(2, 5, 2, 3));
66      }
67  
68      /** */
69      @Test public void testGrowth() {
70          final OctaveLong matrix = new OctaveLong(3, 3, 3, 3);
71  	// test set and get without resize 
72          matrix.set(42, 2, 2, 2, 2);
73          matrix.set( 1, 3, 2, 2, 2);
74          matrix.set( 2, 2, 3, 2, 2);
75          matrix.set( 3, 2, 2, 3, 2);
76          matrix.set( 4, 2, 2, 2, 3);
77          assertEquals(42, matrix.get(2, 2, 2, 2));
78          assertEquals( 1, matrix.get(3, 2, 2, 2));
79          assertEquals( 2, matrix.get(2, 3, 2, 2));
80          assertEquals( 3, matrix.get(2, 2, 3, 2));
81          assertEquals( 4, matrix.get(2, 2, 2, 3));
82  
83  	// test set and get with resize 
84          matrix.set(314, 4, 5, 7, 6);
85          // assertEquals(42, matrix.get(2, 2, 2, 2));
86          // assertEquals( 1, matrix.get(3, 2, 2, 2));
87          // assertEquals( 2, matrix.get(2, 3, 2, 2));
88          // assertEquals( 3, matrix.get(2, 2, 3, 2));
89          // assertEquals( 4, matrix.get(2, 2, 2, 3));
90          // assertEquals(Math.PI, matrix.get(4, 5, 7, 6));
91  
92  	final OctaveLong matrixB = new OctaveLong(4, 5, 7, 6);
93          matrixB.set(42, 2, 2, 2, 2);
94          matrixB.set( 1, 3, 2, 2, 2);
95          matrixB.set( 2, 2, 3, 2, 2);
96          matrixB.set( 3, 2, 2, 3, 2);
97          matrixB.set( 4, 2, 2, 2, 3);
98          matrixB.set(314, 4, 5, 7, 6);
99   	assertEquals(matrixB, matrix);
100     }
101 
102 
103 
104 }