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    *      https://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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.linear;
24  
25  import java.util.Iterator;
26  
27  import org.hipparchus.exception.LocalizedCoreFormats;
28  import org.hipparchus.exception.MathRuntimeException;
29  import org.hipparchus.linear.RealVector.Entry;
30  import org.junit.Assert;
31  import org.junit.Test;
32  
33  /**
34   * Tests for {@link RealVector}.
35   */
36  public class RealVectorTest extends RealVectorAbstractTest {
37  
38      @Override
39      public RealVector create(final double[] data) {
40          return new RealVectorTestImpl(data);
41      }
42  
43      @Test
44      @Override
45      public void testAppendVector() {
46          checkUnsupported(() -> super.testAppendVector());
47      }
48  
49      @Test
50      @Override
51      public void testAppendScalar() {
52          checkUnsupported(() -> super.testAppendScalar());
53      }
54  
55      @Test
56      @Override
57      public void testGetSubVector() {
58          checkUnsupported(() -> super.testGetSubVector());
59      }
60  
61      @Test
62      @Override
63      public void testGetSubVectorInvalidIndex1() {
64          checkUnsupported(() -> super.testGetSubVectorInvalidIndex1());
65      }
66  
67      @Test
68      @Override
69      public void testGetSubVectorInvalidIndex2() {
70          checkUnsupported(() -> super.testGetSubVectorInvalidIndex2());
71      }
72  
73      @Test
74      @Override
75      public void testGetSubVectorInvalidIndex3() {
76          checkUnsupported(() -> super.testGetSubVectorInvalidIndex3());
77      }
78  
79      @Test
80      @Override
81      public void testGetSubVectorInvalidIndex4() {
82          checkUnsupported(() -> super.testGetSubVectorInvalidIndex4());
83      }
84  
85      @Test
86      @Override
87      public void testSetSubVectorSameType() {
88          checkUnsupported(() -> super.testSetSubVectorSameType());
89      }
90  
91      @Test
92      @Override
93      public void testSetSubVectorMixedType() {
94          checkUnsupported(() -> super.testSetSubVectorMixedType());
95      }
96  
97      @Test
98      @Override
99      public void testSetSubVectorInvalidIndex1() {
100         checkUnsupported(() -> super.testSetSubVectorInvalidIndex1());
101     }
102 
103     @Test
104     @Override
105     public void testSetSubVectorInvalidIndex2() {
106         checkUnsupported(() -> super.testSetSubVectorInvalidIndex2());
107     }
108 
109     @Test
110     @Override
111     public void testSetSubVectorInvalidIndex3() {
112         checkUnsupported(() -> super.testSetSubVectorInvalidIndex3());
113     }
114 
115     @Test
116     @Override
117     public void testIsNaN() {
118         checkUnsupported(() -> super.testIsNaN());
119     }
120 
121     @Test
122     @Override
123     public void testIsInfinite() {
124         checkUnsupported(() -> super.testIsInfinite());
125     }
126 
127     @Test
128     @Override
129     public void testEbeMultiplySameType() {
130         checkUnsupported(() -> super.testEbeMultiplySameType());
131     }
132 
133     @Test
134     @Override
135     public void testEbeMultiplyMixedTypes() {
136         checkUnsupported(() -> super.testEbeMultiplyMixedTypes());
137     }
138 
139     @Test
140     @Override
141     public void testEbeMultiplyDimensionMismatch() {
142         checkUnsupported(() -> super.testEbeMultiplyDimensionMismatch());
143     }
144 
145     @Test
146     @Override
147     public void testEbeDivideSameType() {
148         checkUnsupported(() -> super.testEbeDivideSameType());
149     }
150 
151     @Test
152     @Override
153     public void testEbeDivideMixedTypes() {
154         checkUnsupported(() -> super.testEbeDivideMixedTypes());
155     }
156 
157     @Test
158     @Override
159     public void testEbeDivideDimensionMismatch() {
160         checkUnsupported(() -> super.testEbeDivideDimensionMismatch());
161     }
162 
163     @Test
164     public void testSparseIterator() {
165         /*
166          * For non-default values, use x + 1, x + 2, etc... to make sure that
167          * these values are really different from x.
168          */
169         final double x = getPreferredEntryValue();
170         final double[] data = {
171             x, x + 1d, x, x, x + 2d, x + 3d, x + 4d, x, x, x, x + 5d, x + 6d, x
172         };
173 
174         RealVector v = create(data);
175         Entry e;
176         int i = 0;
177         final double[] nonDefault = {
178             x + 1d, x + 2d, x + 3d, x + 4d, x + 5d, x + 6d
179         };
180         for (Iterator<Entry> it = v.sparseIterator(); it.hasNext(); i++) {
181             e = it.next();
182             Assert.assertEquals(nonDefault[i], e.getValue(), 0);
183         }
184         double [] onlyOne = {x, x + 1d, x};
185         v = create(onlyOne);
186         for(Iterator<Entry> it = v.sparseIterator(); it.hasNext(); ) {
187             e = it.next();
188             Assert.assertEquals(onlyOne[1], e.getValue(), 0);
189         }
190     }
191 
192     @Test
193     @Override
194     public void testSerial() {
195         checkUnsupported(() -> super.testSerial());
196     }
197 
198     @Test
199     @Override
200     public void testEquals() {
201         checkUnsupported(() -> super.testEquals());
202     }
203 
204     interface Thunk {
205         void call();
206     }
207 
208     private void checkUnsupported(final Thunk t) {
209         try {
210             t.call();
211             Assert.fail("an exception should have been thrown");
212         } catch (MathRuntimeException mre) {
213             Assert.assertEquals(LocalizedCoreFormats.UNSUPPORTED_OPERATION, mre.getSpecifier());
214         } catch (UnsupportedOperationException uoe) {
215             // expected
216         }
217     }
218 
219 }