# Path: py_algorithms/challenges/coderbyte/binary_search_tree_lca.py
# class BinarySearchTreeLca:
#     def __call__(self, str_arr: str) -> str:
#         tree_nodes = ast.literal_eval(str_arr[0])
#         _left = int(str_arr[1])
#         _right = int(str_arr[2])
#         _max = max(_left, _right)
#         _min = min(_left, _right)
#         _low = min(tree_nodes.index(_min), tree_nodes.index(_max))
#         xs = []
#         for x in tree_nodes[0:_low + 1]:
#             if x <= _max:
#                 xs.append(x)
#         return max(xs)


from py_algorithms.challenges.coderbyte.binary_search_tree_lca import BinarySearchTreeLca


class TestBinarySearchTreeLca:
    def test_impl(self):
        inputs = {
            5: ["[10, 5, 1, 7, 40, 50]", "1", "7"],
            12: ["[3, 2, 1, 12, 4, 5, 13]", "5", "13"],
            10: ["[10, 5, 1, 7, 40, 50]", "5", "10"],
        }
        f = BinarySearchTreeLca()
        for key in inputs:

# Path: py_algorithms/challenges/coderbyte/binary_search_tree_lca.py
# class BinarySearchTreeLca:
#     def __call__(self, str_arr: str) -> str:
#         tree_nodes = ast.literal_eval(str_arr[0])
#         _left = int(str_arr[1])
#         _right = int(str_arr[2])
#         _max = max(_left, _right)
#         _min = min(_left, _right)
#         _low = min(tree_nodes.index(_min), tree_nodes.index(_max))
#         xs = []
#         for x in tree_nodes[0:_low + 1]:
#             if x <= _max:
#                 xs.append(x)
#         return max(xs)


# Path: tests/py_algorithms/challenges/coderbyte/binary_search_tree_lca_test.py
from py_algorithms.challenges.coderbyte.binary_search_tree_lca import BinarySearchTreeLca



class TestBinarySearchTreeLca:
    def test_impl(self):
        inputs = {
            5: ["[10, 5, 1, 7, 40, 50]", "1", "7"],
            12: ["[3, 2, 1, 12, 4, 5, 13]", "5", "13"],
            10: ["[10, 5, 1, 7, 40, 50]", "5", "10"],
        }
        f = BinarySearchTreeLca()
        for key in inputs:

            assert f(inputs[key]) == key