2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.luftdateninfo.internal;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.luftdateninfo.internal.utils.NumberUtils;
22 * The {@link NumberTest} Test rounding and converting Numbers
24 * @author Bernd Weymann - Initial contribution
27 public class NumberTest {
30 public void testRoundingUp() {
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");
41 public void testRoundingDown() {
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");
52 public void testStringNumbers() {
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");