1   package baseCode.math;
2   
3   import junit.framework.TestCase;
4   import baseCode.math.SpecFunc;
5   
6   /***
7    * 
8    * 
9    * <hr>
10   * <p>
11   * Copyright (c) 2004 Columbia University
12   * 
13   * @author pavlidis
14   * @version $Id: TestSpecFunc.java,v 1.1 2005/03/17 13:58:41 pavlidis Exp $
15   */
16  public class TestSpecFunc extends TestCase {
17  
18     /*
19      * @see TestCase#setUp()
20      */
21     protected void setUp() throws Exception {
22        super.setUp();
23     }
24  
25     /*
26      * @see TestCase#tearDown()
27      */
28     protected void tearDown() throws Exception {
29        super.tearDown();
30     }
31  
32     public final void testHypergeometric() {
33        //hypergeometric( int positives, int successes,
34        //     int negatives, int failures )
35  
36        // dhyper takes : successes, positives, negatives, trials
37        //  dhyper(2, 20, 100, 50);
38        //  [1] 0.0009644643
39        double expectedReturn = 0.0009644643;
40        double actualReturn = SpecFunc.dhyper(2, 20, 100, 50 );
41        assertEquals( expectedReturn, actualReturn, 1e-5 );
42     }
43  
44     public final void testCumHyperGeometric() {
45        //      phyper(2, 20, 100, 50);
46        //      [1] 0.001077697
47        double expectedReturn = 0.001077697;
48        double actualReturn = SpecFunc.phyper( 2, 20, 100, 50, true );
49        assertEquals( expectedReturn, actualReturn, 1e-5 );
50     }
51     
52     public final void testCumHyperGeometricUT() {
53        //      phyper(18, 20, 100, 50, lower.tail=F);
54        //      [1] 7.384185e-08
55  
56        double expectedReturn = 7.384185e-08;
57        double actualReturn = SpecFunc.phyper(18, 20, 100, 50, false );
58        assertEquals( expectedReturn, actualReturn, 1e-5 );
59     }
60     
61     public final void testdBinom() {
62       // dbinom(2, 100, 0.1) == 0.001623197
63        double expectedReturn =  0.001623197;
64        double actualReturn = SpecFunc.dbinom(2, 100, 0.1);
65        assertEquals( expectedReturn, actualReturn, 1e-5 );
66     } 
67     
68  
69  }