# Path: monty/bisect.py
# def index(a, x, atol=None):
#     """Locate the leftmost value exactly equal to x."""
#     i = bs.bisect_left(a, x)
#     if i != len(a):
#         if atol is None:
#             if a[i] == x:
#                 return i
#         else:
#             if abs(a[i] - x) < atol:
#                 return i
#     raise ValueError
# 
# def find_lt(a, x):
#     """Find rightmost value less than x."""
#     i = bs.bisect_left(a, x)
#     if i:
#         return i - 1
#     raise ValueError
# 
# def find_le(a, x):
#     """Find rightmost value less than or equal to x."""
#     i = bs.bisect_right(a, x)
#     if i:
#         return i - 1
#     raise ValueError
# 
# def find_gt(a, x):
#     """Find leftmost value greater than x."""
#     i = bs.bisect_right(a, x)
#     if i != len(a):
#         return i
#     raise ValueError
# 
# def find_ge(a, x):
#     """Find leftmost item greater than or equal to x."""
#     i = bs.bisect_left(a, x)
#     if i != len(a):
#         return i
#     raise ValueError


import unittest
from monty.bisect import index, find_lt, find_le, find_gt, find_ge



class FuncTestCase(unittest.TestCase):
    def test_funcs(self):
        l = [0, 1, 2, 3, 4]
        self.assertEqual(index(l, 1), 1)
        self.assertEqual(find_lt(l, 1), 0)
        self.assertEqual(find_gt(l, 1), 2)
        self.assertEqual(find_le(l, 1), 1)
        self.assertEqual(find_ge(l, 2), 2)
        # self.assertEqual(index([0, 1, 1.5, 2], 1.501, atol=0.1), 4)


if __name__ == "__main__":

# Path: monty/bisect.py
# def index(a, x, atol=None):
#     """Locate the leftmost value exactly equal to x."""
#     i = bs.bisect_left(a, x)
#     if i != len(a):
#         if atol is None:
#             if a[i] == x:
#                 return i
#         else:
#             if abs(a[i] - x) < atol:
#                 return i
#     raise ValueError
# 
# def find_lt(a, x):
#     """Find rightmost value less than x."""
#     i = bs.bisect_left(a, x)
#     if i:
#         return i - 1
#     raise ValueError
# 
# def find_le(a, x):
#     """Find rightmost value less than or equal to x."""
#     i = bs.bisect_right(a, x)
#     if i:
#         return i - 1
#     raise ValueError
# 
# def find_gt(a, x):
#     """Find leftmost value greater than x."""
#     i = bs.bisect_right(a, x)
#     if i != len(a):
#         return i
#     raise ValueError
# 
# def find_ge(a, x):
#     """Find leftmost item greater than or equal to x."""
#     i = bs.bisect_left(a, x)
#     if i != len(a):
#         return i
#     raise ValueError


# Path: tests/test_bisect.py
import unittest
from monty.bisect import index, find_lt, find_le, find_gt, find_ge




class FuncTestCase(unittest.TestCase):
    def test_funcs(self):
        l = [0, 1, 2, 3, 4]
        self.assertEqual(index(l, 1), 1)
        self.assertEqual(find_lt(l, 1), 0)
        self.assertEqual(find_gt(l, 1), 2)
        self.assertEqual(find_le(l, 1), 1)
        self.assertEqual(find_ge(l, 2), 2)
        # self.assertEqual(index([0, 1, 1.5, 2], 1.501, atol=0.1), 4)


if __name__ == "__main__":

    unittest.main()