mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
51be4ac4b9
Summary: Mangling `sys.path` in `.py` tests could break tests running with `buck` opt build. Because the bundled extensions won't be used, but files in the working copy will. It's okay-ish for pure Python extensions. But native extensions will have problems. Reviewed By: ryanmce Differential Revision: D6974954 fbshipit-source-id: 8a7f3d86e5c2fbf16cfcc971743d99585fe61b99
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import unittest
|
|
import silenttestrunner
|
|
|
|
class BisectTests(unittest.TestCase):
|
|
def testSimple(self):
|
|
self._assertBisect([1], 1, 0)
|
|
self._assertBisect([1, 2], 1, 0)
|
|
self._assertBisect([1, 2], 2, 1)
|
|
|
|
def testEmptyArray(self):
|
|
self._assertBisect([], 1, None)
|
|
|
|
def testTwoEqual(self):
|
|
self._assertBisect([], 1, None)
|
|
self._assertBisect([1, 1], 1, 0)
|
|
self._assertBisect([1, 1, 1], 1, 0)
|
|
|
|
def testAllBigger(self):
|
|
self._assertBisect([2], 1, None)
|
|
self._assertBisect([2, 3], 1, None)
|
|
self._assertBisect([2, 3, 4], 1, None)
|
|
|
|
def testBig(self):
|
|
array = range(0, 10)
|
|
for i in array:
|
|
self._assertBisect(array, i, i)
|
|
array = range(0, 11)
|
|
for i in array:
|
|
self._assertBisect(array, i, i)
|
|
|
|
def testNotFound(self):
|
|
array = range(0, 10)
|
|
self._assertBisect(array, 10, None)
|
|
array = range(0, 11)
|
|
self._assertBisect(array, 11, None)
|
|
array = range(0, 10, 2)
|
|
self._assertBisect(array, 1, None)
|
|
|
|
def _assertBisect(self, array, value, result):
|
|
|
|
def comp(index, value):
|
|
if array[index] < value:
|
|
return -1
|
|
elif array[index] == value:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
self.assertEqual(bisect(0, len(array) - 1, comp, value), result)
|
|
|
|
if __name__ == '__main__':
|
|
from hgext.generic_bisect import bisect
|
|
silenttestrunner.main(__name__)
|