1   /* Contributed in the public domain.
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  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.BeforeEach;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.Utils;
23  
24  import java.io.IOException;
25  
26  public class TruncatedCcsdsFormatterTest {
27  
28      @Test
29      public void testNumber() {
30  
31          Assertions.assertEquals("4.940656E-318",          new TruncatedCcsdsFormatter().toString( 4.940656E-318d));
32          Assertions.assertEquals("1.18575755E-316",        new TruncatedCcsdsFormatter().toString( 1.18575755E-316d));
33          Assertions.assertEquals("2.989102097996E-312",    new TruncatedCcsdsFormatter().toString( 2.989102097996E-312d));
34          Assertions.assertEquals("9.0608011534336E15",     new TruncatedCcsdsFormatter().toString( 9.0608011534336E15d));
35          Assertions.assertEquals("4.708356024711512E18",   new TruncatedCcsdsFormatter().toString( 4.708356024711512E18d));
36          Assertions.assertEquals("9.409340012568248E18",   new TruncatedCcsdsFormatter().toString( 9.409340012568248E18d));
37          Assertions.assertEquals("1.853150176586857E21",  new TruncatedCcsdsFormatter().toString( 1.8531501765868567E21d));
38          Assertions.assertEquals("-3.347727380279489E33",  new TruncatedCcsdsFormatter().toString(-3.347727380279489E33d));
39  
40          // These are truncated
41          Assertions.assertEquals("-6.974182466276096E19", new TruncatedCcsdsFormatter().toString(-6.9741824662760956E19d));
42          Assertions.assertEquals("4.381605060114784E18",  new TruncatedCcsdsFormatter().toString( 4.3816050601147837E18d));
43          Assertions.assertEquals("1.0E-3",  new TruncatedCcsdsFormatter().toString( .00100d));
44          Assertions.assertEquals("1.0E0",  new TruncatedCcsdsFormatter().toString( 1.0000000000000004d));
45      }
46  
47      @Test
48      public void testDateNonTruncated() {
49          Assertions.assertEquals("2021-03-26T09:45:32.4576",
50                  new TruncatedCcsdsFormatter().toString(2021, 3, 26, 9, 45, 32.4576d));
51          Assertions.assertEquals("2021-03-26T09:45:00.00000000000001",
52                  new TruncatedCcsdsFormatter().toString(2021, 3, 26, 9, 45, 1.0e-14d));
53      }
54  
55      @Test
56      public void testDateTruncated() throws IOException {
57          Assertions.assertEquals("2021-03-26T09:45:00.0",
58                  new TruncatedCcsdsFormatter().toString(2021, 3, 26, 9, 45, 1.0e-16d));
59          Assertions.assertEquals("2021-03-26T09:45:12.34567891234568",
60                  new TruncatedCcsdsFormatter().toString(2021, 3, 26, 9, 45, 12.3456789123456789d));
61      }
62  
63  
64      /**
65       * This test contains edge cases that are or would result in invalid date times.
66       * This demonstrates that the formatter will NOT catch/correct any invalid inputs and shows how the invalid inputs will
67       * be formatted.
68       */
69      @Test
70      public void testInvalidEdgeCases() {
71          Assertions.assertEquals("2021-03-26T09:45:59.99999999999999",
72                  new TruncatedCcsdsFormatter().toString(2021, 3, 26, 9, 45, Math.nextDown(60.0)));
73          Assertions.assertEquals("20210-300-260T900:450:600.0",
74                  new TruncatedCcsdsFormatter().toString(20210, 300, 260, 900, 450, 600.0));
75          Assertions.assertEquals("-2021--3--26T-9:-45:-01.0",
76                  new TruncatedCcsdsFormatter().toString(-2021, -3, -26, -9, -45, -1.0));
77      }
78  
79      @BeforeEach
80      public void setUp() {
81          Utils.setDataRoot("regular-data");
82      }
83  
84  }
85