1   /* Copyright 2022-2025 Thales Alenia Space
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS 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.orekit.bodies;
18  
19  import org.hipparchus.util.FastMath;
20  import org.hipparchus.util.MathUtils;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  
24  import java.util.Locale;
25  
26  /**
27   * Unit tests for {@link SexagesimalAngle}.
28   *
29   * @author Luc Maisonobe
30   *
31   */
32  public class SexagesimalAngleTest {
33  
34      @Test
35      void testZeroDMS() {
36          Assertions.assertEquals(0.0, new SexagesimalAngle(1, 0, 0, 0.0).getAngle(), 1.0e-15);
37      }
38  
39      @Test
40      void testZeroRadians() {
41          final SexagesimalAngle angle = new SexagesimalAngle(0.0);
42          Assertions.assertEquals(1,   angle.getSign());
43          Assertions.assertEquals(0,   angle.getDegree());
44          Assertions.assertEquals(0,   angle.getArcMinute());
45          Assertions.assertEquals(0.0, angle.getArcSecond(), 1.0e-15);
46      }
47  
48      @Test
49      void testPositiveRighAngleDMS() {
50          Assertions.assertEquals(MathUtils.SEMI_PI, new SexagesimalAngle(1, 90, 0, 0.0).getAngle(), 1.0e-15);
51      }
52  
53      @Test
54      void testPositiveRighAngleRadians() {
55          final SexagesimalAngle angle = new SexagesimalAngle(MathUtils.SEMI_PI);
56          Assertions.assertEquals( 1,   angle.getSign());
57          Assertions.assertEquals(90,   angle.getDegree());
58          Assertions.assertEquals( 0,   angle.getArcMinute());
59          Assertions.assertEquals( 0.0, angle.getArcSecond(), 1.0e-15);
60      }
61  
62      @Test
63      void testNegativeRighAngleDMS() {
64          Assertions.assertEquals(-MathUtils.SEMI_PI, new SexagesimalAngle(-1, 90, 0, 0.0).getAngle(), 1.0e-15);
65      }
66  
67      @Test
68      void testNegativeRighAngleRadians() {
69          final SexagesimalAngle angle = new SexagesimalAngle(-MathUtils.SEMI_PI);
70          Assertions.assertEquals(-1,   angle.getSign());
71          Assertions.assertEquals(90,   angle.getDegree());
72          Assertions.assertEquals( 0,   angle.getArcMinute());
73          Assertions.assertEquals( 0.0, angle.getArcSecond(), 1.0e-15);
74      }
75  
76      @Test
77      void testIter() {
78          final String[] expected = new String[] {
79              "00W 10′ 15.0″", "00W 09′ 45.0″", "00W 09′ 15.0″", "00W 08′ 45.0″", "00W 08′ 15.0″", "00W 07′ 45.0″",
80              "00W 07′ 15.0″", "00W 06′ 45.0″", "00W 06′ 15.0″", "00W 05′ 45.0″", "00W 05′ 15.0″", "00W 04′ 45.0″",
81              "00W 04′ 15.0″", "00W 03′ 45.0″", "00W 03′ 15.0″", "00W 02′ 45.0″", "00W 02′ 15.0″", "00W 01′ 45.0″",
82              "00W 01′ 15.0″", "00W 00′ 45.0″", "00W 00′ 15.0″", "00E 00′ 15.0″", "00E 00′ 45.0″", "00E 01′ 15.0″",
83              "00E 01′ 45.0″", "00E 02′ 15.0″", "00E 02′ 45.0″", "00E 03′ 15.0″", "00E 03′ 45.0″", "00E 04′ 15.0″",
84              "00E 04′ 45.0″", "00E 05′ 15.0″", "00E 05′ 45.0″", "00E 06′ 15.0″", "00E 06′ 45.0″", "00E 07′ 15.0″",
85              "00E 07′ 45.0″", "00E 08′ 15.0″", "00E 08′ 45.0″", "00E 09′ 15.0″", "00E 09′ 45.0″", "00E 10′ 15.0″"
86          };
87  
88          for (int i = 0; i < expected.length; i++) {
89              final SexagesimalAngle angle = new SexagesimalAngle(FastMath.toRadians(30.0 / 3600.0) * (i - 20.5));
90              final String formatted = String.format(Locale.US, "%02d%c %02d′ %04.1f″",
91                                                     angle.getDegree(),
92                                                     angle.getSign() < 0 ? 'W' : 'E',
93                                                     angle.getArcMinute(),
94                                                     angle.getArcSecond());
95              Assertions.assertEquals(expected[i], formatted);
96          }
97  
98      }
99  
100 }