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.jupiter.api.Test;
28
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30 import static org.junit.jupiter.api.Assertions.assertFalse;
31 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
32 import static org.junit.jupiter.api.Assertions.assertNotEquals;
33 import static org.junit.jupiter.api.Assertions.assertNotSame;
34 import static org.junit.jupiter.api.Assertions.assertTrue;
35 import static org.junit.jupiter.api.Assertions.fail;
36
37 class S1PointTest {
38
39 @Test
40 void testS1Point() {
41 for (int k = -2; k < 3; ++k) {
42 S1Point p = new S1Point(1.0 + k * MathUtils.TWO_PI);
43 assertEquals(FastMath.cos(1.0), p.getVector().getX(), 1.0e-10);
44 assertEquals(FastMath.sin(1.0), p.getVector().getY(), 1.0e-10);
45 assertFalse(p.isNaN());
46 }
47 }
48
49 @Test
50 void testNaN() {
51 assertTrue(S1Point.NaN.isNaN());
52 assertEquals(S1Point.NaN, new S1Point(Double.NaN));
53 assertNotEquals(S1Point.NaN, new S1Point(1.0));
54 }
55
56 @SuppressWarnings("unlikely-arg-type")
57 @Test
58 void testEquals() {
59 S1Point a = new S1Point(1.0);
60 S1Point b = new S1Point(1.0);
61 assertEquals(a.hashCode(), b.hashCode());
62 assertNotSame(a, b);
63 assertEquals(a, b);
64 assertEquals(a, a);
65 assertNotEquals('a', a);
66 assertEquals(S1Point.NaN, S1Point.NaN);
67 assertEquals(S1Point.NaN, new S1Point(Double.NaN));
68 }
69
70 @Test
71 void testEqualsIeee754() {
72 S1Point a = new S1Point(1.0);
73 S1Point b = new S1Point(1.0);
74 assertEquals(a.hashCode(), b.hashCode());
75 assertNotSame(a, b);
76 assertTrue(a.equalsIeee754(b));
77 assertTrue(a.equalsIeee754(a));
78 assertFalse(a.equalsIeee754('a'));
79 assertFalse(S1Point.NaN.equalsIeee754(S1Point.NaN));
80 assertFalse(S1Point.NaN.equalsIeee754(new S1Point(Double.NaN)));
81 }
82
83 @Test
84 void testDistance() {
85 S1Point a = new S1Point(1.0);
86 S1Point b = new S1Point(a.getAlpha() + MathUtils.SEMI_PI);
87 assertEquals(MathUtils.SEMI_PI, a.distance(b), 1.0e-10);
88 }
89
90 @Test
91 void testSpace() {
92 S1Point a = new S1Point(1.0);
93 assertInstanceOf(Sphere1D.class, a.getSpace());
94 assertEquals(1, a.getSpace().getDimension());
95 try {
96 a.getSpace().getSubSpace();
97 fail("an exception should have been thrown");
98 } catch (MathRuntimeException muoe) {
99
100 }
101 }
102
103 @Test
104 void testMoveTowards() {
105 final S1Point s1 = new S1Point(2.0);
106 final S1Point s2 = new S1Point(4.0);
107 for (double r = 0.0; r <= 1.0; r += FastMath.scalb(1.0, -10)) {
108
109 assertEquals(r * s1.distance(s2), s1.distance(s1.moveTowards(s2, r)), 1.0e-14);
110 }
111 }
112
113 }