View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.math4.legacy.linear;
19  
20  import java.util.Iterator;
21  
22  import org.apache.commons.math4.legacy.linear.RealVector.Entry;
23  import org.junit.Assert;
24  import org.junit.Ignore;
25  import org.junit.Test;
26  
27  /**
28   * Tests for {@link RealVector}.
29   */
30  public class RealVectorTest extends RealVectorAbstractTest{
31  
32      @Override
33      public RealVector create(final double[] data) {
34          return new RealVectorTestImpl(data);
35      }
36  
37      @Test
38      @Ignore("Abstract class RealVector does not implement append(RealVector).")
39      @Override
40      public void testAppendVector() {
41          // Do nothing
42      }
43  
44      @Test
45      @Ignore("Abstract class RealVector does not implement append(double)")
46      @Override
47      public void testAppendScalar() {
48          // Do nothing
49      }
50  
51      @Test
52      @Ignore("Abstract class RealVector does not implement getSubvector(int, int)")
53      @Override
54      public void testGetSubVector() {
55          // Do nothing
56      }
57  
58      @Test
59      @Ignore("Abstract class RealVector does not implement getSubvector(int, int)")
60      @Override
61      public void testGetSubVectorInvalidIndex1() {
62          // Do nothing
63      }
64  
65      @Test
66      @Ignore("Abstract class RealVector does not implement getSubvector(int, int)")
67      @Override
68      public void testGetSubVectorInvalidIndex2() {
69          // Do nothing
70      }
71  
72      @Test
73      @Ignore("Abstract class RealVector does not implement getSubvector(int, int)")
74      @Override
75      public void testGetSubVectorInvalidIndex3() {
76          // Do nothing
77      }
78  
79      @Test
80      @Ignore("Abstract class RealVector does not implement getSubvector(int, int)")
81      @Override
82      public void testGetSubVectorInvalidIndex4() {
83          // Do nothing
84      }
85  
86      @Test
87      @Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)")
88      @Override
89      public void testSetSubVectorSameType() {
90          // Do nothing
91      }
92  
93      @Test
94      @Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)")
95      @Override
96      public void testSetSubVectorMixedType() {
97          // Do nothing
98      }
99  
100     @Test
101     @Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)")
102     @Override
103     public void testSetSubVectorInvalidIndex1() {
104         // Do nothing
105     }
106 
107     @Test
108     @Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)")
109     @Override
110     public void testSetSubVectorInvalidIndex2() {
111         // Do nothing
112     }
113 
114     @Test
115     @Ignore("Abstract class RealVector does not implement setSubvector(int, RealVector)")
116     @Override
117     public void testSetSubVectorInvalidIndex3() {
118         // Do nothing
119     }
120 
121     @Test
122     @Ignore("Abstract class RealVector does not implement isNaN()")
123     @Override
124     public void testIsNaN() {
125         // Do nothing
126     }
127 
128     @Test
129     @Ignore("Abstract class RealVector does not implement isNaN()")
130     @Override
131     public void testIsInfinite() {
132         // Do nothing
133     }
134 
135     @Test
136     @Ignore("Abstract class RealVector does not implement ebeMultiply(RealVector)")
137     @Override
138     public void testEbeMultiplySameType() {
139         // Do nothing
140     }
141 
142     @Test
143     @Ignore("Abstract class RealVector does not implement ebeMultiply(RealVector)")
144     @Override
145     public void testEbeMultiplyMixedTypes() {
146         // Do nothing
147     }
148 
149     @Test
150     @Ignore("Abstract class RealVector does not implement ebeMultiply(RealVector)")
151     @Override
152     public void testEbeMultiplyDimensionMismatch() {
153         // Do nothing
154     }
155 
156     @Test
157     @Ignore("Abstract class RealVector does not implement ebeDivide(RealVector)")
158     @Override
159     public void testEbeDivideSameType() {
160         // Do nothing
161     }
162 
163     @Test
164     @Ignore("Abstract class RealVector does not implement ebeDivide(RealVector)")
165     @Override
166     public void testEbeDivideMixedTypes() {
167         // Do nothing
168     }
169 
170     @Test
171     @Ignore("Abstract class RealVector does not implement ebeDivide(RealVector)")
172     @Override
173     public void testEbeDivideDimensionMismatch() {
174         // Do nothing
175     }
176 
177     @Test
178     @Ignore("Abstract class RealVector does not implement getL1Norm()")
179     @Override
180     public void testGetL1Norm() {
181         // Do nothing
182     }
183 
184     @Test
185     @Ignore("Abstract class RealVector does not implement getLInfNorm()")
186     @Override
187     public void testGetLInfNorm() {
188         // Do nothing
189     }
190 
191     @Test
192     public void testSparseIterator() {
193         /*
194          * For non-default values, use x + 1, x + 2, etc... to make sure that
195          * these values are really different from x.
196          */
197         final double x = getPreferredEntryValue();
198         final double[] data = {
199             x, x + 1d, x, x, x + 2d, x + 3d, x + 4d, x, x, x, x + 5d, x + 6d, x
200         };
201 
202         RealVector v = create(data);
203         Entry e;
204         int i = 0;
205         final double[] nonDefault = {
206             x + 1d, x + 2d, x + 3d, x + 4d, x + 5d, x + 6d
207         };
208         for (Iterator<Entry> it = v.sparseIterator(); it.hasNext(); i++) {
209             e = it.next();
210             Assert.assertEquals(nonDefault[i], e.getValue(), 0);
211         }
212         double [] onlyOne = {x, x + 1d, x};
213         v = create(onlyOne);
214         for(Iterator<Entry> it = v.sparseIterator(); it.hasNext();) {
215             e = it.next();
216             Assert.assertEquals(onlyOne[1], e.getValue(), 0);
217         }
218     }
219 
220     @Test
221     @Ignore("Abstract class RealVector is not serializable.")
222     @Override
223     public void testSerial() {
224         // Do nothing
225     }
226 
227     @Test
228     @Ignore("Abstract class RealVector does not override equals(Object).")
229     @Override
230     public void testEquals() {
231         // Do nothing
232     }
233 }