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
18 package org.apache.commons.math.distribution;
19
20 /**
21 * Test cases for CauchyDistribution.
22 * Extends ContinuousDistributionAbstractTest. See class javadoc for
23 * ContinuousDistributionAbstractTest for details.
24 *
25 * @version $Revision: 545192 $ $Date: 2007-06-07 07:35:04 -0700 (Thu, 07 Jun 2007) $
26 */
27 public class CauchyDistributionTest extends ContinuousDistributionAbstractTest {
28
29 /**
30 * Constructor for CauchyDistributionTest.
31 * @param arg0
32 */
33 public CauchyDistributionTest(String arg0) {
34 super(arg0);
35 }
36
37 //-------------- Implementations for abstract methods -----------------------
38
39 /** Creates the default continuous distribution instance to use in tests. */
40 public ContinuousDistribution makeDistribution() {
41 return new CauchyDistributionImpl(1.2, 2.1);
42 }
43
44 /** Creates the default cumulative probability distribution test input values */
45 public double[] makeCumulativeTestPoints() {
46 // quantiles computed using Mathematica
47 return new double[] {-667.2485619d, -65.6230835d, -25.48302995d,
48 -12.05887818d, -5.263135428d, 7.663135428d, 14.45887818d,
49 27.88302995d, 68.0230835d, 669.6485619d};
50 }
51
52 /** Creates the default cumulative probability density test expected values */
53 public double[] makeCumulativeTestValues() {
54 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.900d, 0.950d,
55 0.975d, 0.990d, 0.999d};
56 }
57
58 //---------------------------- Additional test cases -------------------------
59
60 public void testInverseCumulativeProbabilityExtremes() throws Exception {
61 setInverseCumulativeTestPoints(new double[] {0.0, 1.0});
62 setInverseCumulativeTestValues(
63 new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY});
64 verifyInverseCumulativeProbabilities();
65 }
66
67 public void testMedian() {
68 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
69 double expected = Math.random();
70 distribution.setMedian(expected);
71 assertEquals(expected, distribution.getMedian(), 0.0);
72 }
73
74 public void testScale() {
75 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
76 double expected = Math.random();
77 distribution.setScale(expected);
78 assertEquals(expected, distribution.getScale(), 0.0);
79 }
80
81 public void testSetScale() {
82 CauchyDistribution distribution = (CauchyDistribution) getDistribution();
83 try {
84 distribution.setScale(0.0);
85 fail("Can not have 0.0 scale.");
86 } catch (IllegalArgumentException ex) {
87 // success
88 }
89
90 try {
91 distribution.setScale(-1.0);
92 fail("Can not have negative scale.");
93 } catch (IllegalArgumentException ex) {
94 // success
95 }
96 }
97 }