# Path: tibanna/nnested_array.py
# def combine_two(a, b, delimiter='/'):
#     """returns an n-nested array of strings a+delimiter+b
#     a and b (e.g. uuids and object_keys) can be a singlet,
#     an array, an array of arrays or an array of arrays of arrays ...
#     example:
#     >>> a = ['a','b',['c','d']]
#     >>> b = ['e','f',['g','h']]
#     >>> combine_two(a, b)
#     ['a/e','b/f',['c/g','d/h']]
#     """
#     if isinstance(a, list):
#         if not isinstance(b, list):
#             raise Exception("can't combine list and non-list")
#         if len(a) != len(b):
#             raise Exception("Can't combine lists of different lengths")
#         return [combine_two(a_, b_) for a_, b_, in zip(a, b)]
#     else:
#         return(str(a) + delimiter + str(b))
# 
# def run_on_nested_arrays2(a, b, func, **param):
#     """run func on each pair of element in a and b:
#     a and b can be singlets, an array, an array of arrays, an array of arrays of arrays ...
#     The return value is a flattened array
#     """
#     if isinstance(a, list):
#         if not isinstance(b, list):
#             raise Exception("can't combine list and non-list")
#         if len(a) != len(b):
#             raise Exception("Can't combine lists of different lengths")
#         return([run_on_nested_arrays2(a_, b_, func, **param) for a_, b_ in zip(a, b)])
#     else:
#         return(func(a, b, **param))


from tibanna.nnested_array import (
    combine_two,
    run_on_nested_arrays2
)

def test_combine_two():
    x = combine_two('a', 'b')
    assert x == 'a/b'
    x = combine_two(['a1', 'a2'], ['b1', 'b2'])
    assert x == ['a1/b1', 'a2/b2']
    x = combine_two([['a1', 'a2'], ['b1', 'b2']], [['c1', 'c2'], ['d1', 'd2']])
    assert x == [['a1/c1', 'a2/c2'], ['b1/d1', 'b2/d2']]
    x = combine_two([[['a1', 'a2'], ['b1', 'b2']], [['c1', 'c2'], ['d1', 'd2']]],
                    [[['e1', 'e2'], ['f1', 'f2']], [['g1', 'g2'], ['h1', 'h2']]])
    assert x == [[['a1/e1', 'a2/e2'], ['b1/f1', 'b2/f2']],
                 [['c1/g1', 'c2/g2'], ['d1/h1', 'd2/h2']]]


def test_run_on_nested_arrays2():
    def sum0(a, b):
        return(a + b)
    x = run_on_nested_arrays2(1, 2, sum0)
    assert x == 3
    x = run_on_nested_arrays2([1, 2], [3, 4], sum0)
    assert x == [4, 6]

# Path: tibanna/nnested_array.py
# def combine_two(a, b, delimiter='/'):
#     """returns an n-nested array of strings a+delimiter+b
#     a and b (e.g. uuids and object_keys) can be a singlet,
#     an array, an array of arrays or an array of arrays of arrays ...
#     example:
#     >>> a = ['a','b',['c','d']]
#     >>> b = ['e','f',['g','h']]
#     >>> combine_two(a, b)
#     ['a/e','b/f',['c/g','d/h']]
#     """
#     if isinstance(a, list):
#         if not isinstance(b, list):
#             raise Exception("can't combine list and non-list")
#         if len(a) != len(b):
#             raise Exception("Can't combine lists of different lengths")
#         return [combine_two(a_, b_) for a_, b_, in zip(a, b)]
#     else:
#         return(str(a) + delimiter + str(b))
# 
# def run_on_nested_arrays2(a, b, func, **param):
#     """run func on each pair of element in a and b:
#     a and b can be singlets, an array, an array of arrays, an array of arrays of arrays ...
#     The return value is a flattened array
#     """
#     if isinstance(a, list):
#         if not isinstance(b, list):
#             raise Exception("can't combine list and non-list")
#         if len(a) != len(b):
#             raise Exception("Can't combine lists of different lengths")
#         return([run_on_nested_arrays2(a_, b_, func, **param) for a_, b_ in zip(a, b)])
#     else:
#         return(func(a, b, **param))


# Path: tests/tibanna/unicorn/test_nnested_array.py
from tibanna.nnested_array import (
    combine_two,
    run_on_nested_arrays2
)


def test_combine_two():
    x = combine_two('a', 'b')
    assert x == 'a/b'
    x = combine_two(['a1', 'a2'], ['b1', 'b2'])
    assert x == ['a1/b1', 'a2/b2']
    x = combine_two([['a1', 'a2'], ['b1', 'b2']], [['c1', 'c2'], ['d1', 'd2']])
    assert x == [['a1/c1', 'a2/c2'], ['b1/d1', 'b2/d2']]
    x = combine_two([[['a1', 'a2'], ['b1', 'b2']], [['c1', 'c2'], ['d1', 'd2']]],
                    [[['e1', 'e2'], ['f1', 'f2']], [['g1', 'g2'], ['h1', 'h2']]])
    assert x == [[['a1/e1', 'a2/e2'], ['b1/f1', 'b2/f2']],
                 [['c1/g1', 'c2/g2'], ['d1/h1', 'd2/h2']]]


def test_run_on_nested_arrays2():
    def sum0(a, b):
        return(a + b)
    x = run_on_nested_arrays2(1, 2, sum0)
    assert x == 3
    x = run_on_nested_arrays2([1, 2], [3, 4], sum0)
    assert x == [4, 6]

    x = run_on_nested_arrays2([[1, 2], [3, 4]], [[5, 6], [7, 8]], sum0)