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 package org.apache.commons.math3.geometry.spherical.oned;
18 
19 import org.apache.commons.math3.exception.MathUnsupportedOperationException;
20 import org.apache.commons.math3.util.FastMath;
21 import org.apache.commons.math3.util.MathUtils;
22 import org.junit.Assert;
23 import org.junit.Test;
24 
25 public class S1PointTest {
26 
27     @Test
testS1Point()28     public void testS1Point() {
29         for (int k = -2; k < 3; ++k) {
30             S1Point p = new S1Point(1.0 + k * MathUtils.TWO_PI);
31             Assert.assertEquals(FastMath.cos(1.0), p.getVector().getX(), 1.0e-10);
32             Assert.assertEquals(FastMath.sin(1.0), p.getVector().getY(), 1.0e-10);
33             Assert.assertFalse(p.isNaN());
34         }
35     }
36 
37     @Test
testNaN()38     public void testNaN() {
39         Assert.assertTrue(S1Point.NaN.isNaN());
40         Assert.assertTrue(S1Point.NaN.equals(new S1Point(Double.NaN)));
41         Assert.assertFalse(new S1Point(1.0).equals(S1Point.NaN));
42     }
43 
44     @Test
testEquals()45     public void testEquals() {
46         S1Point a = new S1Point(1.0);
47         S1Point b = new S1Point(1.0);
48         Assert.assertEquals(a.hashCode(), b.hashCode());
49         Assert.assertFalse(a == b);
50         Assert.assertTrue(a.equals(b));
51         Assert.assertTrue(a.equals(a));
52         Assert.assertFalse(a.equals('a'));
53     }
54 
55     @Test
testDistance()56     public void testDistance() {
57         S1Point a = new S1Point(1.0);
58         S1Point b = new S1Point(a.getAlpha() + 0.5 * FastMath.PI);
59         Assert.assertEquals(0.5 * FastMath.PI, a.distance(b), 1.0e-10);
60     }
61 
62     @Test
testSpace()63     public void testSpace() {
64         S1Point a = new S1Point(1.0);
65         Assert.assertTrue(a.getSpace() instanceof Sphere1D);
66         Assert.assertEquals(1, a.getSpace().getDimension());
67         try {
68             a.getSpace().getSubSpace();
69             Assert.fail("an exception should have been thrown");
70         } catch (MathUnsupportedOperationException muoe) {
71             // expected
72         }
73     }
74 
75 }
76