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