<reponame>zhubaiyuan/learning-algorithms<gh_stars>0
import unittest

from algs07_binary_array_search.binary_array_search import binary_array_search, performance_binary_array_search


class TestBinaryArraySearch(unittest.TestCase):
    def test_binary_array_search(self):
        nums = []
        self.assertEqual(-1, binary_array_search(nums, 6))
        nums = [6]
        self.assertEqual(0, binary_array_search(nums, 6))
        self.assertEqual(-1, binary_array_search(nums, 2))
        self.assertEqual(-2, binary_array_search(nums, 11))
        nums = [2, 4, 6]
        self.assertEqual(-1, binary_array_search(nums, 1))
        self.assertEqual(-2, binary_array_search(nums, 3))
        self.assertEqual(-3, binary_array_search(nums, 5))
        self.assertEqual(-4, binary_array_search(nums, 7))

    def test_performance_binary_array_search(self):
        tbl = performance_binary_array_search(max_k=10, output=False)
        self.assertTrue(tbl.entry(32, 'T(N)') < tbl.entry(512, 'T(N)'))


if __name__ == '__main__':
    unittest.main()

import unittest

from algs07_binary_array_search.binary_array_search import binary_array_search, performance_binary_array_search


class TestBinaryArraySearch(unittest.TestCase):
    def test_binary_array_search(self):
        nums = []
        self.assertEqual(-1, binary_array_search(nums, 6))
        nums = [6]
        self.assertEqual(0, binary_array_search(nums, 6))
        self.assertEqual(-1, binary_array_search(nums, 2))
        self.assertEqual(-2, binary_array_search(nums, 11))
        nums = [2, 4, 6]
        self.assertEqual(-1, binary_array_search(nums, 1))
        self.assertEqual(-2, binary_array_search(nums, 3))
        self.assertEqual(-3, binary_array_search(nums, 5))
        self.assertEqual(-4, binary_array_search(nums, 7))

    def test_performance_binary_array_search(self):
        tbl = performance_binary_array_search(max_k=10, output=False)
        self.assertTrue(tbl.entry(32, 'T(N)') < tbl.entry(512, 'T(N)'))


if __name__ == '__main__':
    unittest.main()