def test_ascending_data(self): ary = arange(10.0) # inside bounds self.assert_(bin_search(ary, 0.0, 1) == 0) self.assert_(bin_search(ary, 5.0, 1) == 5) self.assert_(bin_search(ary, 9.0, 1) == 9) # out of bounds self.assert_(bin_search(ary, 10.0, 1) == -1) self.assert_(bin_search(ary, -1.0, 1) == -1) self.assert_(bin_search(ary, 9.00001, 1) == -1) self.assert_(bin_search(ary, -0.00001, 1) == -1) # rounding self.assert_(bin_search(ary, 5.1, 1) == 5) self.assert_(bin_search(ary, 4.9, 1) == 4) return
def test_ascending_data(self): ary = arange(10.0) # inside bounds self.assertEqual(bin_search(ary, 0.0, 1), 0) self.assertEqual(bin_search(ary, 5.0, 1), 5) self.assertEqual(bin_search(ary, 9.0, 1), 9) # out of bounds self.assertEqual(bin_search(ary, 10.0, 1), -1) self.assertEqual(bin_search(ary, -1.0, 1), -1) self.assertEqual(bin_search(ary, 9.00001, 1), -1) self.assertEqual(bin_search(ary, -0.00001, 1), -1) # rounding self.assertEqual(bin_search(ary, 5.1, 1), 5) self.assertEqual(bin_search(ary, 4.9, 1), 4)