def test_pre_status(self): """测试结果中的is_pre""" a = [1, 2, [3, 4, [5, 6]]] rst = [ite.value[0] for ite in tree(a, dir='downup') if ite.is_pre()] print('Result is: ' + str(rst)) assert rst == [[1, 2, [3, 4, [5, 6]]], 1, 2, [3, 4, [5, 6]], 3, 4, [5, 6], 5, 6]
def test_array_basic(self): """基本数据遍历""" a = [10, 20, 30] rst = [] for _ in range(5): rst += [n.value[0] for n in tree(a)][1:] assert rst == [10, 20, 30] * 5
def test_up(self): a = [10, 20, [30, 40, [50, 60]]] rst = [n.value[0] for n in tree(a, dir='up')] print("Result is: " + str(rst)) assert rst == [ 10, 20, 30, 40, 50, 60, [50, 60], [30, 40, [50, 60]], [10, 20, [30, 40, [50, 60]]] ]
def test_down_up(self): """DOWN-UP全遍历测试""" a = [10, 20, [30, 40, [50, 60]]] rst = [n.value[0] for n in tree(a, dir='downup')] print("Result is: " + str(rst)) assert rst == [[10, 20, [30, 40, [50, 60]]], 10, 20, [30, 40, [50, 60]], 30, 40, [50, 60], 50, 60, [50, 60], [30, 40, [50, 60]], [10, 20, [30, 40, [50, 60]]]]
def test_tree_basic(self): """数组全遍历""" a = [10, 20, 30] rst = [] for i in range(5): rst += [n.value[0] for n in tree(a)] if i == 0: print("Result is: " + str(rst)) assert rst == [[10, 20, 30], 10, 20, 30] * 5
def test_down(self): a = [10, 20, [30, 40, [50, 60]]] rst = [n.value[0] for n in tree(a, dir='down')] print("Result is: " + str(rst)) assert rst == [ [10, 20, [30, 40, [50, 60]]], 10, 20, [30, 40, [50, 60]], 30, 40, [50, 60], 50, 60, ]
def test_index_basic(self): """基本的index测试""" a = [10, 20, [30, 40], 50] rst = [n.value[1].idx for n in tree(a, index())] assert rst == [[], [0], [1], [2], [2, 0], [2, 1], [3]]
def test_all_flat(self): a = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]] rst = [ite.value[0] for ite in tree(a) if ite.is_leaf()] print('Result is: ' + str(rst)) assert rst == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]