3
from pitivi.application import Pitivi
4
from pitivi.utils.misc import binary_search
5
from common import TestCase
8
class BasicTest(TestCase):
10
Basic test to create the proper creation of the Pitivi object
13
def testBinarySearch(self):
14
# binary_search always returns an index, so we do the comparison here
15
def found(A, result, value):
16
if ((result < len(A)) and (A[result] == value)):
21
for offset in xrange(1, 5):
22
for length in xrange(1, 2049, 300):
23
A = [i * offset for i in xrange(0, length)]
25
## check negative hits
27
# search value too low
28
# error if value is found
29
# if search returns non-negative index, fail
31
self.assertFalse(found(A, binary_search(A, value), value))
33
# search value too high
34
# error if value is found
35
# if search returns non-negative index, fail
37
self.assertFalse(found(A, binary_search(A, value), value))
39
## check positive hits
40
for i, a in enumerate(A):
41
# error if value is NOT found
42
# if search does not return correct value, fail
43
self.assertEquals(binary_search(A, A[i]), i)
45
if __name__ == "__main__":