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  package org.hipparchus.geometry.spherical.oned;
23  
24  import org.hipparchus.exception.MathRuntimeException;
25  import org.hipparchus.util.FastMath;
26  import org.hipparchus.util.MathUtils;
27  import org.junit.Assert;
28  import org.junit.Test;
29  
30  public class S1PointTest {
31  
32      @Test
33      public void testS1Point() {
34          for (int k = -2; k < 3; ++k) {
35              S1Point p = new S1Point(1.0 + k * MathUtils.TWO_PI);
36              Assert.assertEquals(FastMath.cos(1.0), p.getVector().getX(), 1.0e-10);
37              Assert.assertEquals(FastMath.sin(1.0), p.getVector().getY(), 1.0e-10);
38              Assert.assertFalse(p.isNaN());
39          }
40      }
41  
42      @Test
43      public void testNaN() {
44          Assert.assertTrue(S1Point.NaN.isNaN());
45          Assert.assertTrue(S1Point.NaN.equals(new S1Point(Double.NaN)));
46          Assert.assertFalse(new S1Point(1.0).equals(S1Point.NaN));
47      }
48  
49      @SuppressWarnings("unlikely-arg-type")
50      @Test
51      public void testEquals() {
52          S1Point a = new S1Point(1.0);
53          S1Point b = new S1Point(1.0);
54          Assert.assertEquals(a.hashCode(), b.hashCode());
55          Assert.assertFalse(a == b);
56          Assert.assertTrue(a.equals(b));
57          Assert.assertTrue(a.equals(a));
58          Assert.assertFalse(a.equals('a'));
59          Assert.assertTrue(S1Point.NaN.equals(S1Point.NaN));
60          Assert.assertTrue(S1Point.NaN.equals(new S1Point(Double.NaN)));
61      }
62  
63      @Test
64      public void testEqualsIeee754() {
65          S1Point a = new S1Point(1.0);
66          S1Point b = new S1Point(1.0);
67          Assert.assertEquals(a.hashCode(), b.hashCode());
68          Assert.assertFalse(a == b);
69          Assert.assertTrue(a.equalsIeee754(b));
70          Assert.assertTrue(a.equalsIeee754(a));
71          Assert.assertFalse(a.equalsIeee754('a'));
72          Assert.assertFalse(S1Point.NaN.equalsIeee754(S1Point.NaN));
73          Assert.assertFalse(S1Point.NaN.equalsIeee754(new S1Point(Double.NaN)));
74      }
75  
76      @Test
77      public void testDistance() {
78          S1Point a = new S1Point(1.0);
79          S1Point b = new S1Point(a.getAlpha() + 0.5 * FastMath.PI);
80          Assert.assertEquals(0.5 * FastMath.PI, a.distance(b), 1.0e-10);
81      }
82  
83      @Test
84      public void testSpace() {
85          S1Point a = new S1Point(1.0);
86          Assert.assertTrue(a.getSpace() instanceof Sphere1D);
87          Assert.assertEquals(1, a.getSpace().getDimension());
88          try {
89              a.getSpace().getSubSpace();
90              Assert.fail("an exception should have been thrown");
91          } catch (MathRuntimeException muoe) {
92              // expected
93          }
94      }
95  
96  }