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