How to use get_bi method in avocado

Best Python code snippet using avocado_python

arbolEnhebrado.py

Source:arbolEnhebrado.py Github

copy

Full Screen

12#Autor: Daniel Brand Taborda345class NodoEnhebrado:6 def __init__(self, d):7 self.dato = d8 self.Li = None9 self.Bi = 010 self.Ld = None11 self.Bd = 01213 def set_dato(self, d):14 self.dato = d1516 def set_Li(self, Li):17 self.Li = Li1819 def set_Bi(self, Bi):20 self.Bi = Bi2122 def set_Ld(self, Ld):23 self.Ld = Ld2425 def set_Bd(self, Bd):26 self.Bd = Bd2728 def get_dato(self):29 return self.dato3031 def get_Li(self):32 return self.Li3334 def get_Bi(self):35 return self.Bi3637 def get_Ld(self):38 return self.Ld3940 def get_Bd(self):41 return self.Bd4243class ArbolEnhebradoPreorden:44 def __init__(self):45 self.raiz = NodoEnhebrado(None)46 self.raiz.set_Li(self.raiz)47 self.raiz.set_Bd(1)48 self.raiz.set_Ld(self.raiz)49 self.lista = []50 self.lista.append(self.raiz)51 self.lista_hojas = []5253 def es_vacio(self):54 return self.raiz.get_Bi() == 05556 def agregar_dato(self, d):57 n = NodoEnhebrado(d)58 if self.es_vacio():59 self.raiz.set_Bi(1)60 self.raiz.set_Li(n)61 return62 p = self.raiz.get_Li()63 q = None64 while p is not None:65 if p.get_dato() == d: return66 q = p67 if d >= p.get_dato():68 p = p.get_Ld()69 else:70 p = p.get_Li()71 if d > q.get_dato():72 q.set_Ld(n)73 q.set_Bd(1)74 else:75 q.set_Li(n)76 q.set_Bi(1)7778 def listar_preorden(self, R):79 if R is None: return80 self.lista.append(R)81 self.listar_preorden(R.get_Li())82 self.listar_preorden(R.get_Ld())8384 def enhebrar_preorden(self):85 if self.es_vacio(): return86 self.listar_preorden(self.raiz.get_Li())87 for i in range(len(self.lista)):88 if self.lista[i].get_Bi == 0: self.lista[i].set_Li(self.lista[i-1])89 if self.lista[i].get_Bd == 0:90 if i == len(self.lista) - 1: self.lista[i].set_Ld(self.lista[0])91 else: self.lista[i].set_Ld(self.lista[i+1])9293 def listar_hojas(self, R, c):94 if R.get_Bd() == 0 and R.get_Bi() == 0:95 self.lista_hojas.append([R, c])96 return97 if R.get_Bi() == 1: self.listar_hojas(R.get_Li(), c + 1)98 if R.get_Bd() == 1: self.listar_hojas(R.get_Ld(), c + 1)99100print("Bienvenido, a continuación ingrese valores ENTEROS para llenar el árbol binario enhebrado.")101arbol = ArbolEnhebradoPreorden()102n = int(input("Ingrese la cantidad de valores que desea ingresar al árbol: "))103p = 0104while p != n:105 valor = int(input("Ingresar dato: "))106 arbol.agregar_dato(valor)107 p = p + 1108arbol.enhebrar_preorden()109arbol.listar_hojas(arbol.raiz.get_Li(), 1)110a = arbol.lista_hojas111print("La distancia entre valores del árbol se mide dependiendo del nivel en el que se encuentre la hoja.")112print("Si el valor es positivo, significa que el nivel del valor es mayor.")113print("Si el valor es 0, significa que los valores están en el mismo nivel.")114print("si el valor es negativo, significa que el nivel del valor es menos.")115for i in range(len(a) - 1):116 for b in range(i+1, len(a) - 1):117 m = str(a[i][1] - a[b][1])118 a1 = str(a[i][0].get_dato())119 a2 = str(a[b][0].get_dato())120 print("La distancia entre el dato " + a1 + " y el dato " + a2 + " es: " + m)121 ...

Full Screen

Full Screen

lab2.py

Source:lab2.py Github

copy

Full Screen

1import numpy2import math34A = [[2, 0, 1],5 [-2, 1, -1],6 [0, 1, -1]]78A_init = A.copy()910L = numpy.zeros([3, 3], dtype=float)11U = numpy.zeros([3, 3], dtype=float)1213for i in range(0, len(L)):14 L[i][i] = 1151617# ex118def get_element_L(i_int, j, A_int, L_int, U_int):19 suma = 020 for t in range(0, j):21 suma += L_int[i_int][t] * U_int[t][j]22 return (A_int[i_int][j] - suma) / U_int[j][j]232425def compute_line_L(i_int, A_int, L_int, U_int):26 for j in range(0, i_int):27 L_int[i_int][j] = get_element_L(i_int, j, A_int, L_int, U_int)282930def get_element_U(i_int, j, A_int, L_int, U_int):31 suma = 032 for t in range(0, i_int):33 suma += L_int[i_int][t] * U_int[t][j]34 return (A_int[i_int][j] - suma) / L_int[i_int][i_int]353637def compute_line_U(i_int, A_int, L_int, U_int):38 for j in range(i, len(A_int)):39 U_int[i_int][j] = get_element_U(i_int, j, A_int, L_int, U_int)404142for i in range(0, len(A)):43 compute_line_U(i, A, L, U)44 if not i == 2:45 compute_line_L(i + 1, A, L, U)4647print("Ex1:\nL:\n", L)48print("U:\n", U)49print("\n")505152# print(numpy.dot(L, U))535455# 256def ex_2(L_int, U_int):57 det_L = numpy.linalg.det(L_int)58 det_U = numpy.linalg.det(U_int)59 print("Ex2:\ndet(A) = ", det_L * det_U)606162ex_2(L, U)63print("\n")6465# 366b = [0, 0, 1]67nDim = 368sol_x_inf = [0, 0, 0]69sol_x_sup = [0, 0, 0]707172def get_solution_inferior_matrix(i, A, b):73 get_bi = 074 for j in range(0, i):75 get_bi += A[i][j] * sol_x_inf[j]76 sol_x_inf[i] = b[i] - get_bi777879def get_solution_superior_matrix(i, A, y):80 get_bi = 081 y = numpy.array(y)82 for j in reversed(range(i, len(A))):83 get_bi += A[i][j] * sol_x_sup[j]84 sol_x_sup[i] = (y[i] - get_bi) / A[i][i]858687for i in range(nDim):88 get_solution_inferior_matrix(i, L, b)89for i in reversed(range(nDim)):90 get_solution_superior_matrix(i, U, sol_x_inf)9192print("Ex3:\nx inferior:\n", sol_x_inf)93print("x superior:\n", sol_x_sup)94print("\n")959697# ex498def norme(v):99 return math.sqrt(sum([x * x for x in v]))100101102def check_norme(A_init, x_LU, b_init):103 A_init = numpy.array(A_init)104 x_LU = numpy.array(x_LU)105 z = A_init.dot(x_LU) - b_init106 return norme(z)107108109norma = check_norme(A_init, sol_x_sup, b)110print("Ex4:\nNorma:\n", norma)111print("\n")112113114# ex5115x = numpy.linalg.solve(A, b)116A_inv = numpy.linalg.inv(A)117print("Ex5:\nx:\n", x)118print("A inversa:\n", A_inv)119120121def get_norms(x_LU, A, b):122 A = numpy.array(A).astype(float)123 A_inv = numpy.linalg.inv(A)124 x_lib = numpy.linalg.solve(A_inv, b)125 norm1 = norme(x_LU - x_lib)126 norm2 = norme(x_LU - numpy.dot(A_inv, b))127 return norm1, norm2128129130print("Norme:\n", get_norms(sol_x_sup, A_init, b))131print("\n")132133134# ex6135def invers(A):136 A_inv_LU = numpy.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])137 for i in range(len(A)):138 e_i = [0] * len(A)139 e_i[i] = 1140 for j in range(len(A)):141 get_solution_inferior_matrix(j, L, e_i)142 for j in reversed(range(len(A))):143 get_solution_superior_matrix(j, U, sol_x_inf)144 A_inv_LU[i] = sol_x_sup145 return A_inv_LU146147148A_inv_LU = invers(A_init) ...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...12 def test_get_K(self):13 self.assertEqual(final.get_K(5), 3)14 self.assertEqual(final.get_K(34), 6)15 self.assertEqual(final.get_K(18), 5)16 def test_get_bi(self):17 self.assertEqual(final.get_bi(18, 4), 1)18 self.assertEqual(final.get_bi(18, 5), 0)19 self.assertEqual(final.get_bi(18, 6), None)20if __name__ == '__main__':...

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