1   /* Copyright 2002-2022 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;
18  
19  
20  import org.junit.Assert;
21  import org.junit.Test;
22  
23  public class AccurateFormatterTest {
24  
25      @Test
26      public void testNumber() {
27          // these tests come from the RyuDouble tests
28          Assert.assertEquals("4.940656E-318",          AccurateFormatter.format( 4.940656E-318d));
29          Assert.assertEquals("1.18575755E-316",        AccurateFormatter.format( 1.18575755E-316d));
30          Assert.assertEquals("2.989102097996E-312",    AccurateFormatter.format( 2.989102097996E-312d));
31          Assert.assertEquals("9.0608011534336E15",     AccurateFormatter.format( 9.0608011534336E15d));
32          Assert.assertEquals("4.708356024711512E18",   AccurateFormatter.format( 4.708356024711512E18));
33          Assert.assertEquals("9.409340012568248E18",   AccurateFormatter.format( 9.409340012568248E18));
34          Assert.assertEquals("1.8531501765868567E21",  AccurateFormatter.format( 1.8531501765868567E21));
35          Assert.assertEquals("-3.347727380279489E33",  AccurateFormatter.format(-3.347727380279489E33));
36          Assert.assertEquals("-6.9741824662760956E19", AccurateFormatter.format(-6.9741824662760956E19));
37          Assert.assertEquals("4.3816050601147837E18",  AccurateFormatter.format( 4.3816050601147837E18));
38      }
39  
40      @Test
41      public void testDateNonTruncated() {
42          Assert.assertEquals("2021-03-26T09:45:32.4576",
43                              AccurateFormatter.format(2021, 3, 26, 9, 45, 32.4576));
44          Assert.assertEquals("2021-03-26T09:45:00.00000000000001",
45                              AccurateFormatter.format(2021, 3, 26, 9, 45, 1.0e-14));
46      }
47  
48      @Test
49      public void testDateTruncated() {
50          Assert.assertEquals("2021-03-26T09:45:00.0",
51                              AccurateFormatter.format(2021, 3, 26, 9, 45, 1.0e-16));
52      }
53  
54  }
55