1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
93 }
94 }
95
96 }