How to use set_parent method in fMBT

Best Python code snippet using fMBT_python

test_p2_tree_height.py

Source:test_p2_tree_height.py Github

copy

Full Screen

...20 assert cathy.parent is None21 root.add_child(cathy)22 assert cathy in root.children23 assert cathy.parent is root24 def test_set_parent(self):25 """Test Node.set_parent method."""26 root = Node('Les')27 cathy = Node('Cathy')28 assert root.children == []29 assert cathy.parent is None30 cathy.set_parent(root)31 assert cathy in root.children32 assert cathy.parent is root33 def test_depth_first_traversal(self):34 """Test Node.depth_first_traversal method."""35 root = Node('Les')36 cathy = Node('Cathy')37 alex = Node('Alex')38 frank = Node('Frank')39 cathy.add_child(alex)40 cathy.add_child(frank)41 cathy.set_parent(root)42 sam = Node('Sam')43 nancy = Node('Nancy')44 sam.add_child(nancy)45 sam.set_parent(root)46 violet = Node('Violet')47 tony = Node('Tony')48 wendy = Node('Wendy')49 violet.add_child(tony)50 violet.add_child(wendy)51 violet.set_parent(sam)52 assert list(root.depth_first_traversal()) == [53 root, sam, violet, wendy, tony, nancy, cathy, frank, alex54 ]55 def test_breadth_first_traversal(self):56 """Test Node.breadth_first_traversal method."""57 root = Node('Les')58 cathy = Node('Cathy')59 alex = Node('Alex')60 frank = Node('Frank')61 cathy.add_child(alex)62 cathy.add_child(frank)63 cathy.set_parent(root)64 sam = Node('Sam')65 nancy = Node('Nancy')66 sam.add_child(nancy)67 sam.set_parent(root)68 violet = Node('Violet')69 tony = Node('Tony')70 wendy = Node('Wendy')71 violet.add_child(tony)72 violet.add_child(wendy)73 violet.set_parent(sam)74 assert list(root.breadth_first_traversal()) == [75 root,76 cathy, sam,77 alex, frank,78 nancy, violet,79 tony, wendy80 ]81 def test_get_height(self):82 """Test Node.get_height method."""83 root = Node('Les')84 assert root.get_height() == 185 cathy = Node('Cathy')86 cathy.add_child(Node('Alex'))87 cathy.add_child(Node('Frank'))88 cathy.set_parent(root)89 sam = Node('Sam')90 sam.add_child(Node('Nancy'))91 sam.set_parent(root)92 violet = Node('Violet')93 violet.add_child(Node('Tony'))94 violet.add_child(Node('Wendy'))95 violet.set_parent(sam)96 assert root.get_height() == 497 assert cathy.get_height() == 298 assert sam.get_height() == 399 assert violet.get_height() == 2100 def test_get_size(self):101 """Test Node.get_size method."""102 root = Node('Les')103 assert root.get_size() == 1104 cathy = Node('Cathy')105 cathy.add_child(Node('Alex'))106 cathy.add_child(Node('Frank'))107 cathy.set_parent(root)108 sam = Node('Sam')109 sam.add_child(Node('Nancy'))110 sam.set_parent(root)111 violet = Node('Violet')112 violet.add_child(Node('Tony'))113 violet.add_child(Node('Wendy'))114 violet.set_parent(sam)115 assert root.get_size() == 9116 assert cathy.get_size() == 3117 assert sam.get_size() == 5118 assert violet.get_size() == 3119class TestSolution:120 """Test Problem 2 solution."""121 @pytest.mark.parametrize('example,expected', [122 ('4 -1 4 1 1', 3),123 ('-1 0 4 0 3', 4),124 ])125 def test_examples(self, example, expected):126 """Test examples given in problem statement."""127 assert solve_string(example) == expected128 def test_very_high(self):...

Full Screen

Full Screen

cousin.py

Source:cousin.py Github

copy

Full Screen

...15 >>> a = Node("a")16 >>> b = Node("b")17 >>> c = Node("c")18 >>> d = Node("d")19 >>> b.set_parent(a)20 >>> c.set_parent(a)21 >>> d.set_parent(a)22 >>> e = Node("e")23 >>> f = Node("f")24 >>> g = Node("g")25 >>> h = Node("h")26 >>> i = Node("i")27 >>> j = Node("j")28 >>> e.set_parent(b)29 >>> f.set_parent(b)30 >>> g.set_parent(c)31 >>> h.set_parent(c)32 >>> i.set_parent(d)33 >>> j.set_parent(d)34 >>> k = Node("k")35 >>> l = Node("l")36 >>> k.set_parent(f)37 >>> l.set_parent(h)38Let's find the cousins for b::39 >>> b.cousins() == {c, d}40 True41 >>> c.cousins() == {b, d}42 True43 >>> e.cousins() == {f, g, h, i, j}44 True45 >>> k.cousins() == {l}46 True47The root node has no cousins::48 >>> a.cousins() == set()49 True50"""51class Node(object):52 """Doubly-linked node in a tree.53 >>> na = Node("na")54 >>> nb1 = Node("nb1")55 >>> nb2 = Node("nb2")56 >>> nb1.set_parent(na)57 >>> nb2.set_parent(na)58 >>> na.children59 [<Node nb1>, <Node nb2>]60 >>> nb1.parent61 <Node na>62 """63 parent = None64 def __init__(self, data):65 self.children = []66 self.data = data67 def __repr__(self):68 return "<Node %s>" % self.data69 def set_parent(self, parent):70 """Set parent of this node.71 Also sets the children of the parent to include this node.72 """73 self.parent = parent74 parent.children.append(self)75 def cousins(self):76 """Find nodes on the same level as this node."""77if __name__ == '__main__':78 import doctest79 if doctest.testmod().failed == 0:...

Full Screen

Full Screen

ontologynode_test.py

Source:ontologynode_test.py Github

copy

Full Screen

...14l = OntologyNode('Baker Brook')15m = OntologyNode('Bathurst')16n = OntologyNode('Dieppe')1718b.set_parent(a)19a.add_child(b)20c.set_parent(a)21a.add_child(c)22d.set_parent(b)23b.add_child(d)24e.set_parent(b)25b.add_child(e)26k.set_parent(b)27b.add_child(k)28f.set_parent(d)29d.add_child(f)30g.set_parent(d)31d.add_child(g)32h.set_parent(e)33e.add_child(h)34i.set_parent(e)35e.add_child(i)36j.set_parent(e)37e.add_child(j)38l.set_parent(k)39k.add_child(l)40m.set_parent(k)41k.add_child(m)42n.set_parent(k)43k.add_child(n)4445root = a4647print(' '.join(get_ancestors(root, f)))48print(' '.join(get_all_leafnodes(root, f)))49print(' '.join(get_all_descendants(root, d)))50# print(getUpper(root,k,list))51l = get_all_descendants(root, d)52print('l is :', ' '.join([e for e in l]))53assert b.get_level() == 1 # b is Canada54assert value_to_node(a, "ON") == d # d is ON5556assert get_node_by_level(root, f, 2).get_value() == "ON" # f is Hamilton ...

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 fMBT 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