1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.lang.math; 18 19 import junit.framework.TestCase; 20 21 /** 22 * Unit tests {@link org.apache.commons.lang.math.IEEE754rUtils}. 23 * 24 * @version $Id: IEEE754rUtilsTest.java 905246 2010-02-01 10:55:38Z niallp $ 25 */ 26 public class IEEE754rUtilsTest extends TestCase { 27 testLang381()28 public void testLang381() { 29 assertEquals(1.2, IEEE754rUtils.min(1.2, 2.5, Double.NaN), 0.01); 30 assertEquals(2.5, IEEE754rUtils.max(1.2, 2.5, Double.NaN), 0.01); 31 assertTrue(Double.isNaN(IEEE754rUtils.max(Double.NaN, Double.NaN, Double.NaN))); 32 assertEquals(1.2f, IEEE754rUtils.min(1.2f, 2.5f, Float.NaN), 0.01); 33 assertEquals(2.5f, IEEE754rUtils.max(1.2f, 2.5f, Float.NaN), 0.01); 34 assertTrue(Float.isNaN(IEEE754rUtils.max(Float.NaN, Float.NaN, Float.NaN))); 35 36 double[] a = new double[] { 1.2, Double.NaN, 3.7, 27.0, 42.0, Double.NaN }; 37 assertEquals(42.0, IEEE754rUtils.max(a), 0.01); 38 assertEquals(1.2, IEEE754rUtils.min(a), 0.01); 39 40 double[] b = new double[] { Double.NaN, 1.2, Double.NaN, 3.7, 27.0, 42.0, Double.NaN }; 41 assertEquals(42.0, IEEE754rUtils.max(b), 0.01); 42 assertEquals(1.2, IEEE754rUtils.min(b), 0.01); 43 44 float[] aF = new float[] { 1.2f, Float.NaN, 3.7f, 27.0f, 42.0f, Float.NaN }; 45 assertEquals(1.2f, IEEE754rUtils.min(aF), 0.01); 46 assertEquals(42.0f, IEEE754rUtils.max(aF), 0.01); 47 48 float[] bF = new float[] { Float.NaN, 1.2f, Float.NaN, 3.7f, 27.0f, 42.0f, Float.NaN }; 49 assertEquals(1.2f, IEEE754rUtils.min(bF), 0.01); 50 assertEquals(42.0f, IEEE754rUtils.max(bF), 0.01); 51 } 52 testEnforceExceptions()53 public void testEnforceExceptions() { 54 try { 55 IEEE754rUtils.min( (float[]) null); 56 fail("IllegalArgumentException expected for null input"); 57 } catch(IllegalArgumentException iae) { /* expected */ } 58 59 try { 60 IEEE754rUtils.min(new float[0]); 61 fail("IllegalArgumentException expected for empty input"); 62 } catch(IllegalArgumentException iae) { /* expected */ } 63 64 try { 65 IEEE754rUtils.max( (float[]) null); 66 fail("IllegalArgumentException expected for null input"); 67 } catch(IllegalArgumentException iae) { /* expected */ } 68 69 try { 70 IEEE754rUtils.max(new float[0]); 71 fail("IllegalArgumentException expected for empty input"); 72 } catch(IllegalArgumentException iae) { /* expected */ } 73 74 try { 75 IEEE754rUtils.min( (double[]) null); 76 fail("IllegalArgumentException expected for null input"); 77 } catch(IllegalArgumentException iae) { /* expected */ } 78 79 try { 80 IEEE754rUtils.min(new double[0]); 81 fail("IllegalArgumentException expected for empty input"); 82 } catch(IllegalArgumentException iae) { /* expected */ } 83 84 try { 85 IEEE754rUtils.max( (double[]) null); 86 fail("IllegalArgumentException expected for null input"); 87 } catch(IllegalArgumentException iae) { /* expected */ } 88 89 try { 90 IEEE754rUtils.max(new double[0]); 91 fail("IllegalArgumentException expected for empty input"); 92 } catch(IllegalArgumentException iae) { /* expected */ } 93 94 } 95 testConstructorExists()96 public void testConstructorExists() { 97 new IEEE754rUtils(); 98 } 99 100 } 101