How to use get_leaves method in avocado

Best Python code snippet using avocado_python

main_test.py

Source:main_test.py Github

copy

Full Screen

...12 load_leaves,13 get_largest_magnitude_pair,14)15numbers_1 = load_snailfish_numbers([[[[[9, 8], 1], 2], 3], 4])16def test_get_leaves():17 assert get_leaves(numbers_1) == [18 RegularNumber(5, 9),19 RegularNumber(5, 8),20 RegularNumber(4, 1),21 RegularNumber(3, 2),22 RegularNumber(2, 3),23 RegularNumber(1, 4),24 ]25# def test_get_exploded_left():26# assert get_exploded_value(numbers_1, is_right=False) == RegularNumber(9)27# def test_has_right_number_1():28# assert has_regular_number(load_snailfish_numbers([0, 1]), 2, is_right=True) == True29# def test_has_right_number_2():30# assert (31# has_regular_number(load_snailfish_numbers([6, [5, [7, 0]]]), 2, is_right=True)32# == False33# )34def test_explode_1():35 assert explode(get_leaves(numbers_1)) == get_leaves(36 load_snailfish_numbers([[[[0, 9], 2], 3], 4])37 )38def test_explode_2():39 assert explode(40 get_leaves(load_snailfish_numbers([7, [6, [5, [4, [3, 2]]]]]))41 ) == get_leaves(load_snailfish_numbers([7, [6, [5, [7, 0]]]]))42def test_explode_3():43 assert explode(44 get_leaves(load_snailfish_numbers([[6, [5, [4, [3, 2]]]], 1]))45 ) == get_leaves(load_snailfish_numbers([[6, [5, [7, 0]]], 3]))46def test_explode_4():47 assert explode(48 get_leaves(49 load_snailfish_numbers([[3, [2, [1, [7, 3]]]], [6, [5, [4, [3, 2]]]]])50 )51 ) == get_leaves(load_snailfish_numbers([[3, [2, [8, 0]]], [9, [5, [4, [3, 2]]]]]))52def test_explode_5():53 assert explode(54 get_leaves(load_snailfish_numbers([[3, [2, [8, 0]]], [9, [5, [4, [3, 2]]]]]))55 ) == get_leaves(56 load_snailfish_numbers(57 [58 [3, [2, [8, 0]]],59 [9, [5, [7, 0]]],60 ]61 )62 )63def test_explode_6():64 assert explode(65 get_leaves(load_snailfish_numbers([[6, [5, [4, [3, 2]]]], [1, 2]]))66 ) == get_leaves(load_snailfish_numbers([[6, [5, [7, 0]]], [3, 2]]))67def test_split_1():68 assert split([RegularNumber(0, 10)]) == [RegularNumber(1, 5), RegularNumber(1, 5)]69def test_split_2():70 assert split([RegularNumber(0, 11)]) == [RegularNumber(1, 5), RegularNumber(1, 6)]71def test_split_3():72 assert split([RegularNumber(0, 12)]) == [RegularNumber(1, 6), RegularNumber(1, 6)]73def test_add():74 assert (75 add(76 get_leaves(load_snailfish_numbers([[[[4, 3], 4], 4], [7, [[8, 4], 9]]])),77 get_leaves(load_snailfish_numbers([1, 1])),78 )79 == get_leaves(load_snailfish_numbers([[[[0, 7], 4], [[7, 8], [6, 0]]], [8, 1]]))80 )81def test_reduce_1():82 input_str = "[1,1]\n[2,2]\n[3,3]\n[4,4]\n"83 assert add_file(input_str) == get_leaves(84 load_snailfish_numbers([[[[1, 1], [2, 2]], [3, 3]], [4, 4]])85 )86def test_reduce_2():87 input_str = "[1,1]\n[2,2]\n[3,3]\n[4,4]\n[5,5]\n"88 assert add_file(input_str) == get_leaves(89 load_snailfish_numbers([[[[3, 0], [5, 3]], [4, 4]], [5, 5]])90 )91def test_reduce_3():92 input_str = "[1,1]\n[2,2]\n[3,3]\n[4,4]\n[5,5]\n[6,6]\n"93 assert add_file(input_str) == get_leaves(94 load_snailfish_numbers([[[[5, 0], [7, 4]], [5, 5]], [6, 6]])95 )96def test_large_input():97 with open("test.txt") as input_file:98 input = input_file.read()99 assert add_file(input) == get_leaves(100 load_snailfish_numbers(101 [[[[8, 7], [7, 7]], [[8, 6], [7, 7]]], [[[0, 7], [6, 6]], [8, 7]]]102 )103 )104def test_magnitude_1():105 assert get_magnitude(Pair(0, RegularNumber(0, 9), RegularNumber(0, 1))) == 29106def test_magnitude_2():107 assert get_magnitude(Pair(0, RegularNumber(0, 1), RegularNumber(0, 9))) == 21108def test_magnitude_3():109 assert get_magnitude(load_snailfish_numbers([[1, 2], [[3, 4], 5]])) == 143110def test_magnitude_4():111 assert (112 get_magnitude(load_snailfish_numbers([[[[0, 7], 4], [[7, 8], [6, 0]]], [8, 1]]))113 == 1384114 )115def test_magnitude_5():116 assert (117 get_magnitude(load_snailfish_numbers([[[[1, 1], [2, 2]], [3, 3]], [4, 4]]))118 == 445119 )120def test_magnitude_6():121 assert (122 get_magnitude(load_snailfish_numbers([[[[3, 0], [5, 3]], [4, 4]], [5, 5]]))123 == 791124 )125def test_magnitude_7():126 assert (127 get_magnitude(load_snailfish_numbers([[[[5, 0], [7, 4]], [5, 5]], [6, 6]]))128 == 1137129 )130def test_magnitude_8():131 assert (132 get_magnitude(133 load_snailfish_numbers(134 [[[[8, 7], [7, 7]], [[8, 6], [7, 7]]], [[[0, 7], [6, 6]], [8, 7]]]135 )136 )137 == 3488138 )139def test_leaves_to_tree_1():140 tree = load_snailfish_numbers(141 [[[[6, 6], [7, 6]], [[7, 7], [7, 0]]], [[[7, 7], [7, 7]], [[7, 8], [9, 9]]]]142 )143 assert leaves_to_tree(get_leaves(tree)) == tree144def test_leaves_to_tree_2():145 tree = load_snailfish_numbers([[6, [5, [4, [3, 2]]]], [1, 2]])146 assert leaves_to_tree(get_leaves(tree)) == tree147def test_integration():148 with open("test2.txt") as input_file:149 input = input_file.read()150 file_add_out = add_file(input)151 assert file_add_out == get_leaves(152 load_snailfish_numbers(153 [[[[6, 6], [7, 6]], [[7, 7], [7, 0]]], [[[7, 7], [7, 7]], [[7, 8], [9, 9]]]]154 )155 )156 assert get_magnitude(leaves_to_tree(file_add_out)) == 4140157def test_get_largest_magnitude_pair():158 with open("test2.txt") as input_file:159 input = input_file.read()160 leaves = load_leaves(input)...

Full Screen

Full Screen

leaves.py

Source:leaves.py Github

copy

Full Screen

...6from matplotlib.patches import Rectangle7import numpy as np8import subprocess9from common import ALGORITHM_EXAMPLES, RESULT_PATH10def get_leaves(points, algorithm, skewed=False, seed=None, heuristic=False):11 fn_args = locals()12 args = [13 str(ALGORITHM_EXAMPLES),14 "--algorithm", algorithm,15 "--points", str(points),16 ]17 if skewed:18 args.append("--skewed")19 if heuristic:20 args.append("--heuristic")21 if seed is not None:22 args.extend(["--seed", str(seed)])23 result = json.loads(subprocess.check_output(args).decode("utf-8"))24 print("seed for args {} is {}".format(fn_args, result["seed"]))25 return result["leaves"]26def draw_leaves(ax, title, leaves):27 ax.set_title(title)28 ax.set_xlabel("x")29 ax.set_ylabel("y")30 ax.set_xlim(0, 1)31 ax.set_ylim(0, 1)32 cmap = matplotlib.cm.get_cmap("gist_rainbow")33 colors = cmap(np.linspace(0, 1, len(leaves)))34 avg = sum(len(leaf["points"]) for leaf in leaves) / len(leaves)35 print(title, avg)36 for color, leaf in zip(colors, leaves):37 color[3] = 0.538 mbb = leaf["mbb"]39 x = mbb["min"]["x"]40 y = mbb["min"]["y"]41 width = mbb["max"]["x"] - x42 height = mbb["max"]["y"] - y43 ax.add_patch(Rectangle(xy=(x, y), width=width,44 height=height, fill=True, facecolor=color, edgecolor="black"))45def save(fig, path):46 fig.tight_layout()47 fig.savefig(str(path), bbox_inches="tight")48def make_hilbert():49 fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12, 4))50 draw_leaves(ax1, "a)",51 get_leaves(1000, algorithm="hilbert", seed=1380799046))52 draw_leaves(ax2, "b)",53 get_leaves(1000, algorithm="hilbert",54 skewed=True, seed=1821311943))55 draw_leaves(ax3, "c)",56 get_leaves(1000, algorithm="hilbert", skewed=True,57 seed=1821311943, heuristic=True))58 return fig59def make_str():60 fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))61 draw_leaves(ax1, "a)",62 get_leaves(1000, algorithm="str", seed=1380799046))63 draw_leaves(ax2, "b)",64 get_leaves(1000, algorithm="str", skewed=True, seed=1821311943))65 return fig66def make_quickload():67 fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(8, 8))68 draw_leaves(ax1, "a)", get_leaves(69 1000, algorithm="obo", seed="1380799046"))70 draw_leaves(ax2, "b)", get_leaves(71 1000, algorithm="obo", skewed=True, seed=1821311943))72 draw_leaves(ax3, "c)", get_leaves(73 1000, algorithm="quickload", seed="1380799046"))74 draw_leaves(ax4, "d)", get_leaves(75 1000, algorithm="quickload", skewed=True, seed=1821311943))76 return fig77save(make_hilbert(), RESULT_PATH / "hilbert_leaves.pdf")78save(make_str(), RESULT_PATH / "str_leaves.pdf")...

Full Screen

Full Screen

leaf_similar_trees.py

Source:leaf_similar_trees.py Github

copy

Full Screen

...10 :type root1: TreeNode11 :type root2: TreeNode12 :rtype: bool13 """14 return self.get_leaves(root1) == self.get_leaves(root2)15 16 def get_leaves(self, root):17 if root is None:18 return ()19 if root.left is None and root.right is None:20 return (root.val,)21 leaves = ()22 if root.left:23 leaves += self.get_leaves(root.left)24 if root.right:25 leaves += self.get_leaves(root.right)26 return leaves...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful