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  /**
26   * @deprecated since Tobago 3.0.1
27   */
28  @Deprecated
29  public class MathUtilsUnitTest {
30  
31    @Test
32    public void testAdjust() {
33      final double[] d = {6.3, 7.9, 8.7, 9.2, 10.3, 11.6};
34      MathUtils.adjustRemainders(d, 0.0);
35      Assert.assertArrayEquals("mixed", new double[]{6, 8, 9, 9, 10, 12}, d, MathUtils.EPSILON);
36    }
37  
38    @Test
39    public void testAdjust999() {
40      final double[] d = {9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9};
41      MathUtils.adjustRemainders(d, 0.0);
42      Assert.assertArrayEquals(
43          "9.9, ...", new double[]{9, 10, 10, 10, 10, 10, 10, 10, 10, 10}, d, MathUtils.EPSILON);
44    }
45  
46    @Test
47    public void testAdjust111() {
48      final double[] d = {1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1};
49      MathUtils.adjustRemainders(d, 0.0);
50      Assert.assertArrayEquals(
51          "1.1, ...", new double[]{1, 2, 1, 1, 1, 1, 1, 1, 1, 1}, d, MathUtils.EPSILON);
52    }
53  
54    @Test
55    public void testAdjust133() {
56      final double[] d = {1, 1, 1, 1.333333333, 1.333333333, 1.333333333, 1, 1, 1};
57      MathUtils.adjustRemainders(d, 0.0);
58      Assert.assertArrayEquals(
59          "1, ..., 1.333...", new double[]{1, 1, 1, 1, 2, 1, 1, 1, 1}, d, MathUtils.EPSILON);
60    }
61  
62    @Test
63    public void testInitialBias() {
64      final double[] d = {5.5};
65      MathUtils.adjustRemainders(d, 0.5);
66      Assert.assertArrayEquals("initial bias", new double[]{5}, d, MathUtils.EPSILON);
67    }
68  
69  
70    @Test
71    public void testIsZero() {
72      Assert.assertTrue(MathUtils.isZero(0));
73      Assert.assertFalse(MathUtils.isZero(1.0/1000.0));
74      Assert.assertTrue(MathUtils.isZero(1.0/1000000000.0));
75      Assert.assertTrue(MathUtils.isZero(-1.0/1000000000.0));
76    }
77  
78    @Test
79    public void testIsNotZero() {
80      Assert.assertFalse(MathUtils.isNotZero(0));
81      Assert.assertTrue(MathUtils.isNotZero(1.0/1000.0));
82      Assert.assertFalse(MathUtils.isNotZero(1.0/1000000000.0));
83      Assert.assertFalse(MathUtils.isNotZero(-1.0/1000000000.0));
84    }
85  
86    @Test
87    public void testIsInteger() {
88      Assert.assertTrue(MathUtils.isInteger(1.0));
89      Assert.assertTrue(MathUtils.isInteger(0.0));
90      Assert.assertTrue(MathUtils.isInteger(1.0/1000000000.0));
91      Assert.assertFalse(MathUtils.isInteger(1.0/1000.0));
92    }
93  
94    @Test
95    public void testIsNotInteger() {
96      Assert.assertFalse(MathUtils.isNotInteger(1.0));
97      Assert.assertFalse(MathUtils.isNotInteger(0.0));
98      Assert.assertFalse(MathUtils.isNotInteger(1.0/1000000000.0));
99      Assert.assertTrue(MathUtils.isNotInteger(1.0/1000.0));
100   }
101 }