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.optim;
19  
20  import org.apache.commons.math4.legacy.TestUtils;
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  public class PointVectorValuePairTest {
25      @Test
26      public void testAccessors1() {
27          final double[] k = new double[] { 1.0, 2.0, 3.0 };
28          final double[] v = new double[] { 4.0, 5.0 };
29  
30          final PointVectorValuePair pv = new PointVectorValuePair(k, v);
31  
32          final double[] kC = pv.getPoint();
33          kC[0] = 1 - kC[0];
34          final double[] vC = pv.getValue();
35          vC[0] = 1 - vC[0];
36  
37          // Check that "pv" has not been changed.
38          TestUtils.assertEquals("k", k, pv.getPoint(), 0d);
39          TestUtils.assertEquals("v", v, pv.getValue(), 0d);
40      }
41  
42      @Test
43      public void testAccessors2() {
44          final double[] k = new double[] { 1.0, 2.0, 3.0 };
45          final double[] v = new double[] { 4.0, 5.0 };
46  
47          final PointVectorValuePair pv = new PointVectorValuePair(k, v);
48  
49          final double[] kC = pv.getPointRef();
50          kC[0] = 1 - kC[0];
51          final double[] vC = pv.getValueRef();
52          vC[0] = 1 - vC[0];
53  
54          // Check that "pv" has been changed.
55          Assert.assertEquals(kC[0], pv.getPoint()[0], 0d);
56          Assert.assertEquals(vC[0], pv.getValue()[0], 0d);
57      }
58  }