1   /* Copyright 2002-2025 CS GROUP
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.utils.units;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.orekit.errors.OrekitException;
22  import org.orekit.errors.OrekitMessages;
23  
24  /**
25   * Unit tests for {@link Lexer}.
26   *
27   * @author Luc Maisonobe
28   */
29  public class UnitsConverterTest {
30  
31      @Test
32      public void testTime() {
33          final UnitsConverter day2second = new UnitsConverter(Unit.DAY, Unit.SECOND);
34          Assertions.assertEquals(388800.0, day2second.convert(4.5), 1.0e-9);
35      }
36  
37      @Test
38      public void testAngle() {
39          final UnitsConverter rev2deg = new UnitsConverter(Unit.REVOLUTION, Unit.DEGREE);
40          Assertions.assertEquals(360.0, rev2deg.convert(1.0), 1.0e-12);
41      }
42  
43      @Test
44      public void testRotationRate() {
45  
46      }
47  
48      @Test
49      public void testPressure() {
50          final double atm = 1013.25;
51          final Unit mbar  = Unit.parse("mbar");
52          final Unit hPa   = Unit.parse("hPa");
53          final UnitsConverter mbar2hPa = new UnitsConverter(mbar, hPa);
54          Assertions.assertEquals(atm, mbar2hPa.convert(atm), 1.0e-12);
55      }
56  
57      @Test
58      public void testIncompatibleUnits() {
59          try {
60              new UnitsConverter(Unit.parse("km³/s²"), Unit.parse("MΩ"));
61              Assertions.fail("an exception should have been thrown");
62          } catch (OrekitException oe) {
63              Assertions.assertEquals(OrekitMessages.INCOMPATIBLE_UNITS, oe.getSpecifier());
64              Assertions.assertEquals("km³/s²", oe.getParts()[0]);
65              Assertions.assertEquals("MΩ", oe.getParts()[1]);
66          }
67      }
68  
69  }