# Path: pyalgs/algorithms/commons/selecting.py
# class BinarySelection(object):
#     @staticmethod
#     def index_of(a, x, lo=None, hi=None):
#         if not is_sorted(a):
#             raise ValueError('array must be sorted before running selection')
# 
#         if lo is None:
#             lo = 0
#         if hi is None:
#             hi = len(a) - 1
# 
#         while lo <= hi:
#             mid = lo + (hi - lo) // 2
#             if less(x, a[mid]):
#                 hi = mid - 1
#             elif less(a[mid], x):
#                 lo = mid + 1
#             else:
#                 return mid
# 
#         return -1
# 
# Path: pyalgs/algorithms/commons/util.py
# def is_sorted(a):
#     if len(a) <= 1:
#         return True
#     for i in range(1, len(a)):
#         if less(a[i], a[i - 1]):
#             return False
#     return True


import unittest
from pyalgs.algorithms.commons.selecting import BinarySelection
from pyalgs.algorithms.commons.util import is_sorted



class BinarySelectionUnitTest(unittest.TestCase):
    def test_select(self):
        a = [1, 2, 13, 22, 123]
        assert is_sorted(a)

# Path: pyalgs/algorithms/commons/selecting.py
# class BinarySelection(object):
#     @staticmethod
#     def index_of(a, x, lo=None, hi=None):
#         if not is_sorted(a):
#             raise ValueError('array must be sorted before running selection')
# 
#         if lo is None:
#             lo = 0
#         if hi is None:
#             hi = len(a) - 1
# 
#         while lo <= hi:
#             mid = lo + (hi - lo) // 2
#             if less(x, a[mid]):
#                 hi = mid - 1
#             elif less(a[mid], x):
#                 lo = mid + 1
#             else:
#                 return mid
# 
#         return -1
# 
# Path: pyalgs/algorithms/commons/util.py
# def is_sorted(a):
#     if len(a) <= 1:
#         return True
#     for i in range(1, len(a)):
#         if less(a[i], a[i - 1]):
#             return False
#     return True


# Path: tests/algorithms/commons/selecting_unit_test.py
import unittest
from pyalgs.algorithms.commons.selecting import BinarySelection
from pyalgs.algorithms.commons.util import is_sorted




class BinarySelectionUnitTest(unittest.TestCase):
    def test_select(self):
        a = [1, 2, 13, 22, 123]
        assert is_sorted(a)

        print(BinarySelection.index_of(a, 13))