Hypergeometric { public double phyper(int x, int N, int M, int n, boolean lowerTail) { int i; int up; double p; up = Math.min(n, M); p = 0; if (x < up / 2) { for (i = x; i >= 0; i--) p += dhyper(i, N, M, n); if (lowerTail) return p; else return 1 - p; } else { for (i = x + 1; i <= up; i++) p += dhyper(i, N, M, n); if (lowerTail) return 1 - p; else return p; } } Hypergeometric(); double phypergeometric(int n, double p, int k, int r); double phypergeometric(int m, int m_t, int n, int n_t); double dhyper(int x, int N, int M, int n); double phyper(int x, int N, int M, int n, boolean lowerTail); double lNchooseK(int n, int k); double logfact(int i);  }
@Test void test_phyper_overrepresentation() { int N = 60; int n = 13; int n_t = 2; int m_t = 5; double result = hypergeometric.phyper(n_t-1, N, m_t, n, false); assertEquals(0.2945756, result, EPSILON); }
@Test void test_phyper_underrepresentation() { int N = 60; int n = 13; int n_t = 2; int m_t = 5; double result = hypergeometric.phyper(n_t, N, m_t, n, true); assertEquals(0.9370032, result, EPSILON); }