def test_combinations(self): """combinations should return expected results when int as input""" self.assertEqual(combinations(1,1), 1) self.assertEqual(combinations(2,1), 2) self.assertEqual(combinations(3,1), 3) self.assertEqual(combinations(4,1), 4) self.assertEqual(combinations(4,2), 6) self.assertEqual(combinations(4,3), 4) self.assertEqual(combinations(4,4), 1) self.assertEqual(combinations(20,4), 19*17*15) self.assertFloatEqual(combinations(300, 100), 4.1582514632578812e+81)
def test_combinations_float(self): """combinations should use gamma function when floats as input""" self.assertFloatEqual(combinations(1.0,1.0), 1) self.assertFloatEqual(combinations(2.0,1.0), 2) self.assertFloatEqual(combinations(3.0,1.0), 3) self.assertFloatEqual(combinations(4.0,1.0), 4) self.assertFloatEqual(combinations(4.0,2), 6) self.assertFloatEqual(combinations(4,3.0), 4) self.assertFloatEqual(combinations(4.0,4.0), 1) self.assertFloatEqual(combinations(20.0,4.0), 19*17*15) self.assertFloatEqual(combinations(300,100.0),4.1582514632578812e81)
def test_combinations(self): """combinations should return expected results when int as input""" self.assertEqual(combinations(1, 1), 1) self.assertEqual(combinations(2, 1), 2) self.assertEqual(combinations(3, 1), 3) self.assertEqual(combinations(4, 1), 4) self.assertEqual(combinations(4, 2), 6) self.assertEqual(combinations(4, 3), 4) self.assertEqual(combinations(4, 4), 1) self.assertEqual(combinations(20, 4), 19 * 17 * 15) self.assertFloatEqual(combinations(300, 100), 4.1582514632578812e+81)
def test_combinations_float(self): """combinations should use gamma function when floats as input""" self.assertFloatEqual(combinations(1.0, 1.0), 1) self.assertFloatEqual(combinations(2.0, 1.0), 2) self.assertFloatEqual(combinations(3.0, 1.0), 3) self.assertFloatEqual(combinations(4.0, 1.0), 4) self.assertFloatEqual(combinations(4.0, 2), 6) self.assertFloatEqual(combinations(4, 3.0), 4) self.assertFloatEqual(combinations(4.0, 4.0), 1) self.assertFloatEqual(combinations(20.0, 4.0), 19 * 17 * 15) self.assertFloatEqual(combinations(300, 100.0), 4.1582514632578812e81)
def test_combinations_range(self): """combinations should decrease gradually with increasing k""" start = 5 #combinations(10,5) = 252 end = 6 #combinations(10,6) = 210 step = 0.1 lower_lim = 210 upper_lim = 252 previous_value = 252.00001 while start <= end: obs = combinations(10,start) assert lower_lim <= obs <= upper_lim assert obs < previous_value previous_value = obs start += step
def test_combinations_range(self): """combinations should decrease gradually with increasing k""" start = 5 #combinations(10,5) = 252 end = 6 #combinations(10,6) = 210 step = 0.1 lower_lim = 210 upper_lim = 252 previous_value = 252.00001 while start <= end: obs = combinations(10, start) assert lower_lim <= obs <= upper_lim assert obs < previous_value previous_value = obs start += step
def pkolmogorov1x(statistic, n): """Probability function for the one-sided one sample Kolmogorov statistics. Translated from R 2.4.""" statistic = asarray(statistic) if statistic <= 0: return 0.0 if statistic >= 1: return 1.0 to = floor(n * (1 - statistic)) + 1 j = arange(0, to) coeffs = asarray([log(combinations(n, i)) for i in j]) p = sum(exp(coeffs + (n - j) * log(1 - statistic - j / n) + (j - 1) * (log(statistic + j / n)))) return 1 - statistic * p
def pkolmogorov1x(statistic, n): """Probability function for the one-sided one sample Kolmogorov statistics. Translated from R 2.4.""" statistic = asarray(statistic) if statistic <= 0: return 0. if statistic >= 1: return 1. to = floor(n * (1 - statistic)) + 1 j = arange(0, to) coeffs = asarray([log(combinations(n, i)) for i in j]) p = sum(exp(coeffs + (n-j)*log(1-statistic-j/n) + \ (j-1)*(log(statistic+j/n)))) return 1 - statistic * p