1   package baseCode.math;
2   
3   import junit.framework.TestCase;
4   import baseCode.math.KSTest;
5   import baseCode.math.distribution.ProbabilityComputer;
6   import baseCode.math.distribution.UniformProbabilityComputer;
7   import cern.colt.list.DoubleArrayList;
8   
9   /***
10   * <hr>
11   * <p>
12   * Copyright (c) 2004 Columbia University
13   * 
14   * @author pavlidis
15   * @version $Id: TestKSTest.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
16   */
17  public class TestKSTest extends TestCase {
18  
19     // uniform (r)
20     DoubleArrayList x = new DoubleArrayList( new double[] {
21           0.42084388, 0.08428030, 0.51525081, 0.02165163, 0.99627802,
22           0.79237273, 0.52478154, 0.21394388, 0.19654006, 0.88131869
23     } );
24  
25     // normal (n)
26     DoubleArrayList y = new DoubleArrayList( new double[] {
27           -0.09503411, 2.33677197, 0.61934707, 0.83549049, 0.09643316,
28           -0.57449861, -1.40573974, 0.51279445, -0.09593008, 1.48125008
29     } );
30  
31     /*
32      * @see TestCase#setUp()
33      */
34     protected void setUp() throws Exception {
35        super.setUp();
36  
37     }
38  
39     /*
40      * @see TestCase#tearDown()
41      */
42     protected void tearDown() throws Exception {
43        super.tearDown();
44     }
45  
46     public void testKSTestTwoSample() {
47        double actualReturn = KSTest.twoSample( x, y );
48        double expectedReturn = 0.4175; // from R ks.test(x,y)
49        assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
50     }
51  
52     public void testKSTestOneSample() {
53        // ks.test(n, punif, 0, 1)
54  
55        // x<-punif(sort(n)) - (0 : (10-1)) / 10
56        //max(c(x, 1/10 - x))
57  
58       ProbabilityComputer ps = new UniformProbabilityComputer();
59       double actualReturn = KSTest.oneSample(y, ps);
60       double expectedReturn = 0.07698; // D is 0.4036
61       assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
62     }
63  
64  }