]> git.basschouten.com Git - openhab-addons.git/blob
e2206e91d6fcfd062100188b0d1a6d083027379d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.luftdateninfo.internal;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.luftdateninfo.internal.utils.NumberUtils;
20
21 /**
22  * The {@link NumberTest} Test rounding and converting Numbers
23  *
24  * @author Bernd Weymann - Initial contribution
25  */
26 @NonNullByDefault
27 public class NumberTest {
28
29     @Test
30     public void testRoundingUp() {
31         double d1 = 1.95;
32         double d1r2 = NumberUtils.round(d1, 2);
33         assertEquals("1.95", Double.toString(d1r2), "Double 1.95, 2 places");
34         // System.out.println("D1R2 " + d1r2);
35         double d1r1 = NumberUtils.round(d1, 1);
36         // System.out.println("D1R1 " + d1r1);
37         assertEquals("2.0", Double.toString(d1r1), "Double 1.95, 1 place");
38     }
39
40     @Test
41     public void testRoundingDown() {
42         double d1 = 1.94;
43         double d1r2 = NumberUtils.round(d1, 2);
44         assertEquals("1.94", Double.toString(d1r2), "Double 1.94, 2 places");
45         // System.out.println("D1R2 " + d1r2);
46         double d1r1 = NumberUtils.round(d1, 1);
47         // System.out.println("D1R1 " + d1r1);
48         assertEquals("1.9", Double.toString(d1r1), "Double 1.94, 1 place");
49     }
50
51     @Test
52     public void testStringNumbers() {
53         String d1 = "1.94";
54         double d1r2 = NumberUtils.round(d1, 2);
55         assertEquals("1.94", Double.toString(d1r2), "Double 1.94, 2 places");
56         // System.out.println("D1R2 " + d1r2);
57         double d1r1 = NumberUtils.round(d1, 1);
58         // System.out.println("D1R1 " + d1r1);
59         assertEquals("1.9", Double.toString(d1r1), "Double 1.94, 1 place");
60     }
61 }