Path: blob/master/test/jdk/java/math/RoundingMode/RoundingModeTests.java
41152 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4851776 4891522 490533526* @summary Basic tests for the RoundingMode class.27* @author Joseph D. Darcy28*/2930import java.math.RoundingMode;31import java.math.BigDecimal;3233public class RoundingModeTests {34public static void main(String [] argv) {3536// For each member of the family, make sure37// rm == valueOf(rm.toString())3839for(RoundingMode rm: RoundingMode.values()) {40if (rm != RoundingMode.valueOf(rm.toString())) {41throw new RuntimeException("Bad roundtrip conversion of " +42rm.toString());43}44}4546// Test that mapping of old integers to new values is correct47if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) !=48RoundingMode.CEILING) {49throw new RuntimeException("Bad mapping for ROUND_CEILING");50}5152if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) !=53RoundingMode.DOWN) {54throw new RuntimeException("Bad mapping for ROUND_DOWN");55}5657if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) !=58RoundingMode.FLOOR) {59throw new RuntimeException("Bad mapping for ROUND_FLOOR");60}6162if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) !=63RoundingMode.HALF_DOWN) {64throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN");65}6667if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) !=68RoundingMode.HALF_EVEN) {69throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN");70}7172if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) !=73RoundingMode.HALF_UP) {74throw new RuntimeException("Bad mapping for ROUND_HALF_UP");75}7677if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) !=78RoundingMode.UNNECESSARY) {79throw new RuntimeException("Bad mapping for ROUND_UNNECESARY");80}81}82}838485