1   package org.apache.maven.util;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import junit.framework.TestCase;
22  
23  /**
24   * @author Ben Walding
25   *
26   */
27  public class DVSLFormatterTest
28      extends TestCase
29  {
30  
31      public void testFormatNumberSimple()
32      {
33          testFormat( "1", "1", "0" );
34          //        testFormat("1.0", "1", "0.0");
35          //        testFormat("1.00", "1", "0.00");
36          //        testFormat("1.000", "1", "0.000");
37          //        testFormat("1.0000", "1", "0.0000");
38          //
39          //        testFormat("1.10", "1.10", "0.00");
40          //        testFormat("1.100", "1.1000", "0.000");
41          //        testFormat("1.123", "1.1234", "0.000");
42          //        testFormat("1.1234", "1.1234", "0.0000");
43      }
44  
45      public void testFormatNumberNegative()
46      {
47          testFormat( "-1", "-1", "0" );
48          //        testFormat("-1.0", "-1", "0.0");
49          //        testFormat("-1.00", "-1", "0.00");
50          //        testFormat("-1.000", "-1", "0.000");
51          //        testFormat("-1.0000", "-1", "0.0000");
52          //
53          //        testFormat("-1.10", "-1.10", "0.00");
54          //        testFormat("-1.100", "-1.1000", "0.000");
55          //        testFormat("-1.123", "-1.1234", "0.000");
56          //        testFormat("-1.1234", "-1.1234", "0.0000");
57      }
58  
59      public void testFormatNumberPercent()
60      {
61          testFormat( "100%", "1", "0%" );
62          //        testFormat("100.0%", "1", "0.0%");
63          //        testFormat("100.00%", "1", "0.00%");
64          //        testFormat("100.000%", "1", "0.000%");
65          //        testFormat("100.0000%", "1", "0.0000%");
66          //
67          //        testFormat("-110.00%", "-1.10", "0.00%");
68          //        testFormat("-110.000%", "-1.1000", "0.000%");
69          //        testFormat("-112.340%", "-1.1234", "0.000%");
70          //        testFormat("-112.3400%", "-1.1234", "0.0000%");
71  
72          testFormat( "-100%", "-1", "0%" );
73          //        testFormat("-100.0%", "-1", "0.0%");
74          //        testFormat("-100.00%", "-1", "0.00%");
75          //        testFormat("-100.000%", "-1", "0.000%");
76          //        testFormat("-100.0000%", "-1", "0.0000%");
77          //
78          //        testFormat("-110.00%", "-1.10", "0.00%");
79          //        testFormat("-110.000%", "-1.1000", "0.000%");
80          //        testFormat("-112.340%", "-1.1234", "0.000%");
81          //        testFormat("-112.3400%", "-1.1234", "0.0000%");
82      }
83  
84      protected void testFormat( String expected, String value, String pattern )
85      {
86          String actual = DVSLFormatter.formatNumber( value, pattern );
87          String function = "DVSLFormatter.formatNumber(" + value + "," + pattern + ")";
88          if ( !actual.equals( expected ) )
89          {
90              System.out.println( function + "  Actual: " + actual + ", Expected: " + expected );
91          }
92          assertEquals( function, expected, actual );
93      }
94  
95  }