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.utils.formatting;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  
22  public class FastLongFormatterTest {
23  
24      @Test
25      public void testRegularPositive() {
26          Assertions.assertEquals(   "3", new FastLongFormatter(1, false).toString(3));
27          Assertions.assertEquals(   "3", new FastLongFormatter(1, true).toString(3));
28          Assertions.assertEquals(  " 3", new FastLongFormatter(2, false).toString(3));
29          Assertions.assertEquals(  "03", new FastLongFormatter(2, true).toString(3));
30          Assertions.assertEquals( "  3", new FastLongFormatter(3, false).toString(3));
31          Assertions.assertEquals( "003", new FastLongFormatter(3, true).toString(3));
32          Assertions.assertEquals("   3", new FastLongFormatter(4, false).toString(3));
33          Assertions.assertEquals("0003", new FastLongFormatter(4, true).toString(3));
34      }
35  
36      @Test
37      public void testRegularNegative() {
38          Assertions.assertEquals(  "-3", new FastLongFormatter(1, false).toString(-3));
39          Assertions.assertEquals(  "-3", new FastLongFormatter(1, true).toString(-3));
40          Assertions.assertEquals(  "-3", new FastLongFormatter(2, false).toString(-3));
41          Assertions.assertEquals(  "-3", new FastLongFormatter(2, true).toString(-3));
42          Assertions.assertEquals( " -3", new FastLongFormatter(3, false).toString(-3));
43          Assertions.assertEquals( "-03", new FastLongFormatter(3, true).toString(-3));
44          Assertions.assertEquals("  -3", new FastLongFormatter(4, false).toString(-3));
45          Assertions.assertEquals("-003", new FastLongFormatter(4, true).toString(-3));
46      }
47  
48      @Test
49      public void testSpecialNumbers() {
50          Assertions.assertEquals(                   "0", new FastLongFormatter(1, false).toString(0));
51          Assertions.assertEquals(                 "000", new FastLongFormatter(3, true).toString(0));
52          Assertions.assertEquals(                 "  0", new FastLongFormatter(3, false).toString(0));
53          Assertions.assertEquals("-9223372036854775808", new FastLongFormatter(1, false).toString(Long.MIN_VALUE));
54          Assertions.assertEquals( "9223372036854775807", new FastLongFormatter(1, false).toString(Long.MAX_VALUE));
55      }
56  
57      @Test
58      public void testChainCalls() {
59          Assertions.assertEquals(" 1 -02 04",
60                                  new StringBuilder().
61                                          append(new FastLongFormatter(2, false).toString(1)).
62                                          append(' ').
63                                          append(new FastLongFormatter(3, true).toString(-2)).
64                                          append(' ').
65                                          append(new FastLongFormatter(2, true).toString(4)).
66                                          toString());
67      }
68  
69      @Test
70      public void testGetters() {
71          Assertions.assertEquals(4, new FastLongFormatter(4, true).getWidth());
72          Assertions.assertTrue(new FastLongFormatter(4, true).hasZeroPadding());
73          Assertions.assertFalse(new FastLongFormatter(4, false).hasZeroPadding());
74      }
75  
76  }