~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to tests/test_binary_search.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-03-29 15:22:50 UTC
  • mto: (3.1.23 experimental)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20140329152250-flg9onx416bqf3e3
Tags: upstream-0.93
Import upstream version 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest
2
 
import pitivi
3
 
from pitivi.application import Pitivi
4
 
from pitivi.utils.misc import binary_search
5
 
from common import TestCase
6
 
 
7
 
 
8
 
class BasicTest(TestCase):
9
 
    """
10
 
    Basic test to create the proper creation of the Pitivi object
11
 
    """
12
 
 
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)):
17
 
                return result
18
 
            else:
19
 
                return False
20
 
 
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)]
24
 
 
25
 
## check negative hits
26
 
 
27
 
                # search value too low
28
 
                # error if value is found
29
 
                # if search returns non-negative index, fail
30
 
                value = A[0] - 1
31
 
                self.assertFalse(found(A, binary_search(A, value), value))
32
 
 
33
 
                # search value too high
34
 
                # error if value is found
35
 
                # if search returns non-negative index, fail
36
 
                value = A[-1] + 1
37
 
                self.assertFalse(found(A, binary_search(A, value), value))
38
 
 
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)
44
 
 
45
 
if __name__ == "__main__":
46
 
    unittest.main()