    1   /*
    2    * Copyright 2003-2004 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package org.apache.commons.math.distribution;
    18
    19  import junit.framework.TestCase;
    20
    21  /***
    22   * @version $Revision: 1.16 $ $Date: 2004/02/21 21:35:17 $
    23   */
    24  public class DistributionFactoryImplTest extends TestCase {
    25      /*** */
    26      private DistributionFactory factory;
    27
    28  	/***
    29  	 * Constructor for DistributionFactoryImplTest.
    30  	 * @param name
    31  	 */
    32  	public DistributionFactoryImplTest(String name) {
    33  		super(name);
    34  	}
    35  	/***
    36  	 * @throws java.lang.Exception
    37  	 */
    38  	protected void setUp() throws Exception {
    39  		super.setUp();
    40          factory = new DistributionFactoryImpl();
    41  	}
    42
    43  	/***
    44  	 * @throws java.lang.Exception
    45  	 */
    46  	protected void tearDown() throws Exception {
    47          factory = null;
    48  		super.tearDown();
    49  	}
    50
    51      public void testCreateChiSquareDistributionNegative(){
    52          try {
    53              factory.createChiSquareDistribution(-1.0);
    54              fail("negative degrees of freedom.  IllegalArgumentException expected");
    55          } catch (IllegalArgumentException ex) {
    56              ;
    57          }
    58      }
    59
    60      public void testCreateChiSquareDistributionZero(){
    61          try {
    62              factory.createChiSquareDistribution(0.0);
    63              fail("zero degrees of freedom.  IllegalArgumentException expected");
    64          } catch (IllegalArgumentException ex) {
    65              ;
    66          }
    67      }
    68
    69      public void testCreateChiSquareDistributionPositive(){
    70          try {
    71              factory.createChiSquareDistribution(1.0);
    72          } catch (IllegalArgumentException ex) {
    73              fail("positive degrees of freedom.  IllegalArgumentException is not expected");
    74          }
    75      }
    76
    77      public void testCreateFDistributionNegativePositive(){
    78          try {
    79              factory.createFDistribution(-1.0, 1.0);
    80              fail("negative degrees of freedom.  IllegalArgumentException expected");
    81          } catch (IllegalArgumentException ex) {
    82              ;
    83          }
    84      }
    85
    86      public void testCreateFDistributionZeroPositive(){
    87          try {
    88              factory.createFDistribution(0.0, 1.0);
    89              fail("zero degrees of freedom.  IllegalArgumentException expected");
    90          } catch (IllegalArgumentException ex) {
    91              ;
    92          }
    93      }
    94
    95      public void testCreateFDistributionPositiveNegative(){
    96          try {
    97              factory.createFDistribution(1.0, -1.0);
    98              fail("negative degrees of freedom.  IllegalArgumentException expected");
    99          } catch (IllegalArgumentException ex) {
    100             ;
    101         }
    102     }
    103
    104     public void testCreateFDistributionPositiveZero(){
    105         try {
    106             factory.createFDistribution(1.0, 0.0);
    107             fail("zero degrees of freedom.  IllegalArgumentException expected");
    108         } catch (IllegalArgumentException ex) {
    109             ;
    110         }
    111     }
    112
    113     public void testCreateFDistributionPositivePositive(){
    114         try {
    115             factory.createFDistribution(1.0, 1.0);
    116         } catch (IllegalArgumentException ex) {
    117             fail("positive degrees of freedom.  IllegalArgumentException is not expected");
    118         }
    119     }
    120
    121     public void testCreateExponentialDistributionNegative(){
    122         try {
    123             factory.createExponentialDistribution(-1.0);
    124             fail("negative mean.  IllegalArgumentException expected");
    125         } catch (IllegalArgumentException ex) {
    126             ;
    127         }
    128     }
    129
    130     public void testCreateExponentialDistributionZero(){
    131         try {
    132             factory.createExponentialDistribution(0.0);
    133             fail("zero mean.  IllegalArgumentException expected");
    134         } catch (IllegalArgumentException ex) {
    135             ;
    136         }
    137     }
    138
    139     public void testCreateExponentialDistributionPositive(){
    140         try {
    141             factory.createExponentialDistribution(1.0);
    142         } catch (IllegalArgumentException ex) {
    143             fail("positive mean.  IllegalArgumentException is not expected");
    144         }
    145     }
    146
    147     public void testCreateGammaDistributionNegativePositive(){
    148         try {
    149             factory.createGammaDistribution(-1.0, 1.0);
    150             fail("negative alpha.  IllegalArgumentException expected");
    151         } catch (IllegalArgumentException ex) {
    152             ;
    153         }
    154     }
    155
    156     public void testCreateGammaDistributionZeroPositive(){
    157         try {
    158             factory.createGammaDistribution(0.0, 1.0);
    159             fail("zero alpha.  IllegalArgumentException expected");
    160         } catch (IllegalArgumentException ex) {
    161             ;
    162         }
    163     }
    164
    165     public void testCreateGammaDistributionPositiveNegative(){
    166         try {
    167             factory.createGammaDistribution(1.0, -1.0);
    168             fail("negative beta.  IllegalArgumentException expected");
    169         } catch (IllegalArgumentException ex) {
    170             ;
    171         }
    172     }
    173
    174     public void testCreateGammaDistributionPositiveZero(){
    175         try {
    176             factory.createGammaDistribution(1.0, 0.0);
    177             fail("zero beta.  IllegalArgumentException expected");
    178         } catch (IllegalArgumentException ex) {
    179             ;
    180         }
    181     }
    182
    183     public void testCreateGammaDistributionPositivePositive(){
    184         try {
    185             factory.createGammaDistribution(1.0, 1.0);
    186         } catch (IllegalArgumentException ex) {
    187             fail("positive alpah and beta.  IllegalArgumentException is not expected");
    188         }
    189     }
    190
    191     public void testCreateTDistributionNegative(){
    192         try {
    193             factory.createTDistribution(-1.0);
    194             fail("negative degrees of freedom.  IllegalArgumentException expected");
    195         } catch (IllegalArgumentException ex) {
    196             ;
    197         }
    198     }
    199
    200     public void testCreateTDistributionZero(){
    201         try {
    202             factory.createTDistribution(0.0);
    203             fail("zero degrees of freedom.  IllegalArgumentException expected");
    204         } catch (IllegalArgumentException ex) {
    205             ;
    206         }
    207     }
    208
    209     public void testCreateTDistributionPositive(){
    210         try {
    211             factory.createTDistribution(1.0);
    212         } catch (IllegalArgumentException ex) {
    213             fail("positive degrees of freedom.  IllegalArgumentException is not expected");
    214         }
    215     }
    216
    217     public void testBinomialDistributionNegativePositive(){
    218         try {
    219             factory.createBinomialDistribution(-1, 0.5);
    220             fail("negative number of trials.  IllegalArgumentException expected");
    221         } catch (IllegalArgumentException ex ) {
    222         }
    223     }
    224
    225     public void testBinomialDistributionZeroPositive(){
    226         try {
    227             factory.createBinomialDistribution(0, 0.5);
    228         } catch (IllegalArgumentException ex ) {
    229             fail("zero number of trials.  IllegalArgumentException is not expected");
    230         }
    231     }
    232
    233     public void testBinomialDistributionPositivePositive(){
    234         try {
    235             factory.createBinomialDistribution(10, 0.5);
    236         } catch (IllegalArgumentException ex ) {
    237             fail("positive number of trials.  IllegalArgumentException is not expected");
    238         }
    239     }
    240
    241     public void testBinomialDistributionPositiveNegative(){
    242         try {
    243             factory.createBinomialDistribution(10, -0.5);
    244             fail("negative probability of success.  IllegalArgumentException expected");
    245         } catch (IllegalArgumentException ex ) {
    246         }
    247     }
    248
    249     public void testBinomialDistributionPositiveZero(){
    250         try {
    251             factory.createBinomialDistribution(10, 0.0);
    252         } catch (IllegalArgumentException ex ) {
    253             fail("zero probability of success.  IllegalArgumentException is not expected");
    254         }
    255     }
    256
    257     public void testBinomialDistributionPositiveOne(){
    258         try {
    259             factory.createBinomialDistribution(10, 1.0);
    260         } catch (IllegalArgumentException ex ) {
    261             fail("valid probability of success.  IllegalArgumentException is not expected");
    262         }
    263     }
    264
    265     public void testBinomialDistributionPositiveTwo(){
    266         try {
    267             factory.createBinomialDistribution(10, 2.0);
    268             fail("high probability of success.  IllegalArgumentException expected");
    269         } catch (IllegalArgumentException ex ) {
    270         }
    271     }
    272
    273     public void testHypergeometricDistributionNegativePositivePositive(){
    274         try {
    275             factory.createHypergeometricDistribution(-1, 10, 10);
    276             fail("negative population size.  IllegalArgumentException expected");
    277         } catch(IllegalArgumentException ex) {
    278         }
    279     }
    280
    281     public void testHypergeometricDistributionZeroPositivePositive(){
    282         try {
    283             factory.createHypergeometricDistribution(0, 10, 10);
    284             fail("zero population size.  IllegalArgumentException expected");
    285         } catch(IllegalArgumentException ex) {
    286         }
    287     }
    288
    289     public void testHypergeometricDistributionPositiveNegativePositive(){
    290         try {
    291             factory.createHypergeometricDistribution(20, -1, 10);
    292             fail("negative number of successes.  IllegalArgumentException expected");
    293         } catch(IllegalArgumentException ex) {
    294         }
    295     }
    296
    297     public void testHypergeometricDistributionPositiveZeroPositive(){
    298         try {
    299             factory.createHypergeometricDistribution(20, 0, 10);
    300         } catch(IllegalArgumentException ex) {
    301             fail("valid number of successes.  IllegalArgumentException is not expected");
    302         }
    303     }
    304
    305     public void testHypergeometricDistributionPositivePositiveNegative(){
    306         try {
    307             factory.createHypergeometricDistribution(20, 10, -1);
    308             fail("negative sample size.  IllegalArgumentException expected");
    309         } catch(IllegalArgumentException ex) {
    310         }
    311     }
    312
    313     public void testHypergeometricDistributionPositivePositiveZero(){
    314         try {
    315             factory.createHypergeometricDistribution(20, 10, 0);
    316         } catch(IllegalArgumentException ex) {
    317             fail("valid sample size.  IllegalArgumentException is not expected");
    318         }
    319     }
    320 }