View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.layout;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  public class MathUtilsUnitTest {
26  
27    @Test
28    public void testAdjust() {
29      double[] d = {6.3, 7.9, 8.7, 9.2, 10.3, 11.6};
30      MathUtils.adjustRemainders(d, 0.0);
31      Assert.assertArrayEquals("mixed", new double[]{6, 8, 9, 9, 10, 12}, d, MathUtils.EPSILON);
32    }
33  
34    @Test
35    public void testAdjust999() {
36      double[] d = {9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9};
37      MathUtils.adjustRemainders(d, 0.0);
38      Assert.assertArrayEquals(
39          "9.9, ...", new double[]{9, 10, 10, 10, 10, 10, 10, 10, 10, 10}, d, MathUtils.EPSILON);
40    }
41  
42    @Test
43    public void testAdjust111() {
44      double[] d = {1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1};
45      MathUtils.adjustRemainders(d, 0.0);
46      Assert.assertArrayEquals(
47          "1.1, ...", new double[]{1, 2, 1, 1, 1, 1, 1, 1, 1, 1}, d, MathUtils.EPSILON);
48    }
49  
50    @Test
51    public void testAdjust133() {
52      double[] d = {1, 1, 1, 1.333333333, 1.333333333, 1.333333333, 1, 1, 1};
53      MathUtils.adjustRemainders(d, 0.0);
54      Assert.assertArrayEquals(
55          "1, ..., 1.333...", new double[]{1, 1, 1, 1, 2, 1, 1, 1, 1}, d, MathUtils.EPSILON);
56    }
57  
58    @Test
59    public void testInitialBias() {
60      double[] d = {5.5};
61      MathUtils.adjustRemainders(d, 0.5);
62      Assert.assertArrayEquals("initial bias", new double[]{5}, d, MathUtils.EPSILON);
63    }
64  
65  
66    @Test
67    public void testIsZero() {
68      Assert.assertTrue(MathUtils.isZero(0));
69      Assert.assertFalse(MathUtils.isZero(1.0/1000.0));
70      Assert.assertTrue(MathUtils.isZero(1.0/1000000000.0));
71      Assert.assertTrue(MathUtils.isZero(-1.0/1000000000.0));
72    }
73  
74    @Test
75    public void testIsNotZero() {
76      Assert.assertFalse(MathUtils.isNotZero(0));
77      Assert.assertTrue(MathUtils.isNotZero(1.0/1000.0));
78      Assert.assertFalse(MathUtils.isNotZero(1.0/1000000000.0));
79      Assert.assertFalse(MathUtils.isNotZero(-1.0/1000000000.0));
80    }
81  
82    @Test
83    public void testIsInteger() {
84      Assert.assertTrue(MathUtils.isInteger(1.0));
85      Assert.assertTrue(MathUtils.isInteger(0.0));
86      Assert.assertTrue(MathUtils.isInteger(1.0/1000000000.0));
87      Assert.assertFalse(MathUtils.isInteger(1.0/1000.0));
88    }
89  
90    @Test
91    public void testIsNotInteger() {
92      Assert.assertFalse(MathUtils.isNotInteger(1.0));
93      Assert.assertFalse(MathUtils.isNotInteger(0.0));
94      Assert.assertFalse(MathUtils.isNotInteger(1.0/1000000000.0));
95      Assert.assertTrue(MathUtils.isNotInteger(1.0/1000.0));
96    }
97  }