jaroslav@106: /** jaroslav@106: * Back 2 Browser Bytecode Translator jaroslav@1787: * Copyright (C) 2012-2015 Jaroslav Tulach jaroslav@106: * jaroslav@106: * This program is free software: you can redistribute it and/or modify jaroslav@106: * it under the terms of the GNU General Public License as published by jaroslav@106: * the Free Software Foundation, version 2 of the License. jaroslav@106: * jaroslav@106: * This program is distributed in the hope that it will be useful, jaroslav@106: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@106: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@106: * GNU General Public License for more details. jaroslav@106: * jaroslav@106: * You should have received a copy of the GNU General Public License jaroslav@106: * along with this program. Look for COPYING file in the top folder. jaroslav@106: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@106: */ jaroslav@22: package org.apidesign.vm4brwsr; jaroslav@0: jaroslav@789: import org.testng.annotations.AfterClass; jaroslav@103: import org.testng.annotations.BeforeClass; jaroslav@0: import org.testng.annotations.Test; jaroslav@0: jaroslav@1773: /** Checks behavior on Math class. jaroslav@0: * jaroslav@0: * @author Jaroslav Tulach jaroslav@0: */ jaroslav@1773: public class MathTest { jaroslav@600: @Test public void rintNegativeUp() throws Exception { jaroslav@600: final double cnts = -453904.634; jaroslav@1773: assertExec("Should round up to end with 5", mathClass(), "rint__DD", jaroslav@600: -453905.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: jaroslav@1773: protected Class mathClass() { jaroslav@1773: return Math.class; jaroslav@1773: } jaroslav@1773: jaroslav@600: @Test public void rintNegativeDown() throws Exception { jaroslav@600: final double cnts = -453904.434; jaroslav@1773: assertExec("Should round up to end with 4", mathClass(), "rint__DD", jaroslav@600: -453904.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: jaroslav@600: @Test public void rintPositiveUp() throws Exception { jaroslav@600: final double cnts = 453904.634; jaroslav@1773: assertExec("Should round up to end with 5", mathClass(), "rint__DD", jaroslav@600: 453905.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: @Test public void rintPositiveDown() throws Exception { jaroslav@600: final double cnts = 453904.434; jaroslav@1773: assertExec("Should round up to end with 4", mathClass(), "rint__DD", jaroslav@600: 453904.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: @Test public void rintOneHalf() throws Exception { jaroslav@600: final double cnts = 1.5; jaroslav@1773: assertExec("Should round up to end with 2", mathClass(), "rint__DD", jaroslav@600: 2.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: @Test public void rintNegativeOneHalf() throws Exception { jaroslav@600: final double cnts = -1.5; jaroslav@1773: assertExec("Should round up to end with 2", mathClass(), "rint__DD", jaroslav@600: -2.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: @Test public void rintTwoAndHalf() throws Exception { jaroslav@600: final double cnts = 2.5; jaroslav@1773: assertExec("Should round up to end with 2", mathClass(), "rint__DD", jaroslav@600: 2.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@600: @Test public void rintNegativeTwoOneHalf() throws Exception { jaroslav@600: final double cnts = -2.5; jaroslav@1773: assertExec("Should round up to end with 2", mathClass(), "rint__DD", jaroslav@600: -2.0, cnts jaroslav@600: ); jaroslav@600: } jaroslav@3: jaroslav@605: @Test public void ieeeReminder1() throws Exception { jaroslav@1773: assertExec("Same result 1", mathClass(), "IEEEremainder__DDD", jaroslav@605: Math.IEEEremainder(10.0, 4.5), 10.0, 4.5 jaroslav@605: ); jaroslav@605: } jaroslav@605: jaroslav@605: @Test public void ieeeReminder2() throws Exception { jaroslav@1773: assertExec("Same result 1", mathClass(), "IEEEremainder__DDD", jaroslav@605: Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5 jaroslav@605: ); jaroslav@605: } jaroslav@605: jaroslav@708: private static TestVM code; jaroslav@103: jaroslav@103: @BeforeClass jaroslav@789: public static void compileTheCode() throws Exception { jaroslav@103: StringBuilder sb = new StringBuilder(); jaroslav@1773: code = TestVM.compileClass(sb); jaroslav@2: } jaroslav@789: @AfterClass jaroslav@789: public static void releaseTheCode() { jaroslav@789: code = null; jaroslav@789: } jaroslav@2: jaroslav@708: private void assertExec( jaroslav@708: String msg, Class clazz, String method, jaroslav@708: Object ret, Object... args jaroslav@708: ) throws Exception { jaroslav@708: code.assertExec(msg, clazz, method, ret, args); jaroslav@298: } jaroslav@1773: jaroslav@0: }