def test_binFinder(self): bins = [1, 5, 9, 13, 17, 21, 25, 29, 33] bf = binner._binFinder(bins) self.assertEqual(bf(1), 0) self.assertEqual(bf(2), 0) self.assertEqual(bf(21), 5) self.assertEqual(bf(32), 7) self.assert_(bf(33), len(bins)-2) bins = [1, 100, 1000, 10000, 10010, 10020, 10100, 10200] bf = binner._binFinder(bins) self.assertEqual(bf(1.001), 0) self.assertEqual(bf(99.99), 0) self.assertEqual(bf(10009.9), 3) self.assertEqual(bf(10010), 4) self.assertEqual(bf(10011), 4) self.assertEqual(bf(10200), len(bins)-2) bins = [-5.87, -1.74, 1.0/3, 1.1/3, 78.0001, 100124] bf = binner._binFinder(bins) self.assertEqual(bf(-5.86), 0) self.assertEqual(bf(-1.74), 1) self.assertEqual(bf(0.3333), 1) self.assertEqual(bf(1.0/3), 2) self.assertEqual(bf(1.05/3), 2) self.assert_(bf(100124) == len(bins)-2) self.assert_(bf(-5.88) < 0) self.assert_(bf(-78) < 0) self.assert_(bf(200000) > len(bins)-2)
def test_binFinder(self): bins = [1, 5, 9, 13, 17, 21, 25, 29, 33] bf = binner._binFinder(bins) self.assertEqual(bf(1), 0) self.assertEqual(bf(2), 0) self.assertEqual(bf(21), 5) self.assertEqual(bf(32), 7) self.assertTrue(bf(33), len(bins) - 2) bins = [1, 100, 1000, 10000, 10010, 10020, 10100, 10200] bf = binner._binFinder(bins) self.assertEqual(bf(1.001), 0) self.assertEqual(bf(99.99), 0) self.assertEqual(bf(10009.9), 3) self.assertEqual(bf(10010), 4) self.assertEqual(bf(10011), 4) self.assertEqual(bf(10200), len(bins) - 2) bins = [-5.87, -1.74, 1.0 / 3, 1.1 / 3, 78.0001, 100124] bf = binner._binFinder(bins) self.assertEqual(bf(-5.86), 0) self.assertEqual(bf(-1.74), 1) self.assertEqual(bf(0.3333), 1) self.assertEqual(bf(1.0 / 3), 2) self.assertEqual(bf(1.05 / 3), 2) self.assertTrue(bf(100124) == len(bins) - 2) self.assertTrue(bf(-5.88) < 0) self.assertTrue(bf(-78) < 0) self.assertTrue(bf(200000) > len(bins) - 2)
def test_conformity(self): """ The general binary search in the base class binFinder should always give exactly the same result as any implementation for any special case. """ bins = [6, 7, 8, 9, 10, 11, 44, 176, 704, 2816] bf_A = binner._linlogBinFinder(bins) bf_B = binner._binFinder(bins) for value in [6, 11, 100, 176, 704, 2815]: self.assertEqual(bf_A(value), bf_B(value))