1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2013, Alex Băluț <alexandru.balut@gmail.com>
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.
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.
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.
22
from pitivi.utils.misc import binary_search
25
class BinarySearchTest(unittest.TestCase):
27
def testEmptyList(self):
28
self.assertEquals(binary_search([], 10), -1)
30
def testExisting(self):
32
for index, element in enumerate(A):
33
self.assertEquals(binary_search([10, 20, 30], element), index)
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)
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)