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

« back to all changes in this revision

Viewing changes to tests/test_misc.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
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright (c) 2013, Alex Băluț <alexandru.balut@gmail.com>
 
4
#
 
5
# This program is free software; you can redistribute it and/or
 
6
# modify it under the terms of the GNU Lesser General Public
 
7
# License as published by the Free Software Foundation; either
 
8
# version 2.1 of the License, or (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
# Lesser General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Lesser General Public
 
16
# License along with this program; if not, write to the
 
17
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
18
# Boston, MA 02110-1301, USA.
 
19
 
 
20
import unittest
 
21
 
 
22
from pitivi.utils.misc import binary_search
 
23
 
 
24
 
 
25
class BinarySearchTest(unittest.TestCase):
 
26
 
 
27
    def testEmptyList(self):
 
28
        self.assertEquals(binary_search([], 10), -1)
 
29
 
 
30
    def testExisting(self):
 
31
        A = [10, 20, 30]
 
32
        for index, element in enumerate(A):
 
33
            self.assertEquals(binary_search([10, 20, 30], element), index)
 
34
 
 
35
    def testMissingLeft(self):
 
36
        self.assertEquals(binary_search([10, 20, 30], 1), 0)
 
37
        self.assertEquals(binary_search([10, 20, 30], 16), 1)
 
38
        self.assertEquals(binary_search([10, 20, 30], 29), 2)
 
39
 
 
40
    def testMissingRight(self):
 
41
        self.assertEquals(binary_search([10, 20, 30], 11), 0)
 
42
        self.assertEquals(binary_search([10, 20, 30], 24), 1)
 
43
        self.assertEquals(binary_search([10, 20, 30], 40), 2)