001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.math.stat.descriptive.rank;
018    
019    import junit.framework.Test;
020    import junit.framework.TestSuite;
021    
022    import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
023    import org.apache.commons.math.stat.descriptive.UnivariateStatistic;
024    
025    /**
026     * Test cases for the {@link UnivariateStatistic} class.
027     * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
028     */
029    public class MinTest extends StorelessUnivariateStatisticAbstractTest{
030    
031        protected Min stat;
032        
033        /**
034         * @param name
035         */
036        public MinTest(String name) {
037            super(name);
038        }
039    
040        public static Test suite() {
041            TestSuite suite = new TestSuite(MinTest.class);
042            suite.setName("Min  Tests");
043            return suite;
044        }
045        
046        /**
047         * {@inheritDoc}
048         */
049        @Override
050        public UnivariateStatistic getUnivariateStatistic() {
051            return new Min();
052        }
053    
054        /**
055         * {@inheritDoc}
056         */
057        @Override
058        public double expectedValue() {
059            return this.min;
060        }
061        
062        public void testSpecialValues() {
063            double[] testArray = {0d, Double.NaN, Double.POSITIVE_INFINITY, 
064                    Double.NEGATIVE_INFINITY};
065            Min min = new Min();
066            assertTrue(Double.isNaN(min.getResult()));
067            min.increment(testArray[0]);
068            assertEquals(0d, min.getResult(), 0);
069            min.increment(testArray[1]);
070            assertEquals(0d, min.getResult(), 0);
071            min.increment(testArray[2]);
072            assertEquals(0d, min.getResult(), 0);
073            min.increment(testArray[3]);
074            assertEquals(Double.NEGATIVE_INFINITY, min.getResult(), 0);
075            assertEquals(Double.NEGATIVE_INFINITY, min.evaluate(testArray), 0);     
076        }
077    
078        public void testNaNs() {
079            Min min = new Min();
080            double nan = Double.NaN;
081            assertEquals(2d, min.evaluate(new double[]{nan, 2d, 3d}), 0);     
082            assertEquals(1d, min.evaluate(new double[]{1d, nan, 3d}), 0);     
083            assertEquals(1d, min.evaluate(new double[]{1d, 2d, nan}), 0);     
084            assertTrue(Double.isNaN(min.evaluate(new double[]{nan, nan, nan})));     
085        }
086        
087    }