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 * https://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 18 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 23 package org.hipparchus.distribution.continuous; 24 25 import static org.junit.Assert.assertEquals; 26 27 import org.hipparchus.distribution.RealDistribution; 28 import org.junit.Test; 29 30 /** 31 * Test cases for ConstantRealDistribution. 32 */ 33 public class ConstantRealDistributionTest extends RealDistributionAbstractTest { 34 35 // --- Override tolerance ------------------------------------------------- 36 37 @Override 38 public void setUp() { 39 super.setUp(); 40 setTolerance(0); 41 } 42 43 //--- Implementations for abstract methods -------------------------------- 44 45 /** Creates the default uniform real distribution instance to use in tests. */ 46 @Override 47 public ConstantRealDistribution makeDistribution() { 48 return new ConstantRealDistribution(1); 49 } 50 51 /** Creates the default cumulative probability distribution test input values */ 52 @Override 53 public double[] makeCumulativeTestPoints() { 54 return new double[] { 0, 0.5, 1 }; 55 } 56 57 /** Creates the default cumulative probability distribution test expected values */ 58 @Override 59 public double[] makeCumulativeTestValues() { 60 return new double[] { 0, 0, 1 }; 61 } 62 63 /** Creates the default probability density test expected values */ 64 @Override 65 public double[] makeDensityTestValues() { 66 return new double[] { 0, 0, 1 }; 67 } 68 69 /** Override default test, verifying that inverse cum is constant */ 70 @Override 71 @Test 72 public void testInverseCumulativeProbabilities() { 73 RealDistribution dist = getDistribution(); 74 for (double x : getCumulativeTestValues()) { 75 assertEquals(1,dist.inverseCumulativeProbability(x), 0); 76 } 77 } 78 79 //--- Additional test cases ----------------------------------------------- 80 81 @Test 82 public void testMeanVariance() { 83 ConstantRealDistribution dist; 84 85 dist = new ConstantRealDistribution(-1); 86 assertEquals(dist.getNumericalMean(), -1, 0d); 87 assertEquals(dist.getNumericalVariance(), 0, 0d); 88 } 89 90 }