View Javadoc
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  package org.hipparchus.distribution.continuous;
23  
24  import org.hipparchus.util.Precision;
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  /**
29   * Test cases for LaplaceDistribution.
30   */
31  public class LaplaceDistributionTest extends RealDistributionAbstractTest {
32  
33      @Test
34      public void testParameters() {
35          LaplaceDistribution d = makeDistribution();
36          Assert.assertEquals(0, d.getLocation(), Precision.EPSILON);
37          Assert.assertEquals(1, d.getScale(), Precision.EPSILON);
38      }
39  
40      @Test
41      public void testSupport() {
42          LaplaceDistribution d = makeDistribution();
43          Assert.assertTrue(Double.isInfinite(d.getSupportLowerBound()));
44          Assert.assertTrue(Double.isInfinite(d.getSupportUpperBound()));
45          Assert.assertTrue(d.isSupportConnected());
46      }
47  
48      @Override
49      public LaplaceDistribution makeDistribution() {
50          return new LaplaceDistribution(0, 1);
51      }
52  
53      @Override
54      public double[] makeCumulativeTestPoints() {
55          return new double[] {
56              -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5
57          };
58      }
59  
60      @Override
61      public double[] makeDensityTestValues() {
62          return new double[] {
63              0.003368973, 0.009157819, 0.024893534, 0.067667642, 0.183939721,
64              0.500000000, 0.183939721, 0.067667642, 0.024893534, 0.009157819, 0.003368973
65          };
66      }
67  
68      @Override
69      public double[] makeCumulativeTestValues() {
70          return new double[] {
71              0.003368973, 0.009157819, 0.024893534, 0.067667642, 0.183939721,
72              0.500000000, 0.816060279, 0.932332358, 0.975106466, 0.990842181, 0.996631027
73          };
74      }
75  
76  }
77