def ejercicio3_test2():
    s = "Invierto una lista de cinco elementos, creados a partir de nodos"
    valor = 1
    largo = 5
    fallos = test.fails
    n5 = Nodo("Banana", None)
    n4 = Nodo("Manzana", n5)
    n3 = Nodo("Durazno", n4)
    n2 = Nodo("Coco", n3)
    n1 = Nodo("Uva", n2)
    le = LinkedList()
    le.ult = n5
    le.prim = n1
    le.len = largo
    try:
        invertir(le)
        final = ["Banana", "Manzana", "Durazno", "Coco", "Uva"]
        actual = le.prim
        funciono = True
        for i in range(largo):
            if (actual.v != final[i]): funciono = False
            actual = actual.next
        test.print_test(s, funciono and check_list_integrity(le, largo))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
Example #2
0
def ejercicio3_test1():
    s = "Filtro un solo elemento, dejo la lista vacia"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0, "a")
    try:
        nueva = filtrar(linked, no)
        test.print_test(s, nueva.prim is None
                        and check_list_integrity(nueva, 0))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
def ejercicio3_test1():
    s = "Lista de un unico elemento, duplico ese"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0,5)
    try:
        duplicar(linked,5)
        dato1 = linked.prim.v
        dato2 = linked.prim.next.v
        test.print_test(s, dato1 == dato2 and check_list_integrity(linked,2))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
def ejercicio3_test4():
    s = "Invierto la lista de un elemento"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0, "a")
    largo = 1
    try:
        invertir(linked)
        test.print_test(
            s, linked.prim.v == "a" and linked.ult.v == "a"
            and check_list_integrity(linked, largo))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
Example #5
0
def ejercicio3_test3():
    s = "Extiendo una lista vacia al final con una con elementos al principio"
    valor = 1
    fallos = test.fails
    linked1 = LinkedList()
    linked2 = LinkedList()
    linked1.insertar_en_posicion(0,"c")
    linked1.insertar_en_posicion(1,"d")
    linked1.insertar_en_posicion(2,"e")
    funciono=True
    try:
        extend(linked1,linked2)
        l=["c","d","e"]
        actual=linked1.prim
        for i in range(len(l)):
            if actual.v != l[i]: funciono=False
            actual=actual.next    
        test.print_test(s, funciono and check_list_integrity(linked1,linked1.len))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
def ejercicio3_test5_aux():
    s = "Creo una lista con varios elementos y duplico los pares"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    for i in range(100):
        linked.insertar_en_posicion(i,i+1)
    l=[]
    for i in range(1,101):
        l.append(i)
        if(i%2==0): l.append(i)
    try:
        for i in range(2,100,2):
            duplicar(linked,i)
        actual=linked.prim
        for i in range(len(l)):
            if actual.v != l[i]: test.fails += 1
            actual=actual.next
        test.print_test(s, test.fails == fallos and check_list_integrity(linked,len(l)))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
def ejercicio3_test3():
    s = "Pruebo invertir una lista grande de elementos"
    valor = 1
    largo = 101
    fallos = test.fails
    linked = LinkedList()
    for i in range(largo):
        linked.insertar_en_posicion(i, i * 2)
    funciono = True
    final = list(range(200, -1, -2))
    try:
        invertir(linked)
        actual = linked.prim
        for i in range(largo):
            if actual.v != final[i]: funciono = False
            actual = actual.next

        test.print_test(s, funciono
                        and check_list_integrity(linked, len(final)))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
Example #8
0
def ejercicio3_test2():
    s = "Creo una lista chica y filtro todos sus elementos"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0, "a")
    linked.insertar_en_posicion(1, "b")
    linked.insertar_en_posicion(2, "c")
    linked.insertar_en_posicion(3, "d")
    linked.insertar_en_posicion(4, "e")
    try:
        nueva = filtrar(linked, no)
        test.print_test(s, nueva.prim is None
                        and check_list_integrity(nueva, 0))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
def ejercicio3_test5():
    s = "Creo una lista chica y duplico el elemento del princiĆ­o y del final"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0,"e")
    linked.insertar_en_posicion(1,"b")
    linked.insertar_en_posicion(2,"c")
    linked.insertar_en_posicion(3,"d")
    linked.insertar_en_posicion(4,"e")
    try:
        l=["e","e","b","c","d","e","e"]
        duplicar(linked,"e")
        actual=linked.prim
        for i in range(len(l)):
            if actual.v != l[i]: test.fails += 1
            actual=actual.next
        test.print_test(s, test.fails == fallos and check_list_integrity(linked,len(l)))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
Example #10
0
def ejercicio3_test5():
    s = "Creo una lista chica y filtro el primer elemento"
    valor = 1
    fallos = test.fails
    linked = LinkedList()
    linked.insertar_en_posicion(0, "e")
    linked.insertar_en_posicion(1, "b")
    linked.insertar_en_posicion(2, "c")
    linked.insertar_en_posicion(3, "d")
    linked.insertar_en_posicion(4, "a")
    funciono = True
    try:
        nueva = filtrar(linked, no_e)
        l = ["b", "c", "d", "a"]
        actual = nueva.prim
        for i in range(len(l)):
            if actual.v != l[i]: funciono = False
            actual = actual.next

        test.print_test(s, funciono and check_list_integrity(nueva, len(l)))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0
Example #11
0
def ejercicio3_test5():
    s = "Extiendo dos listas muy grandes"
    valor = 1
    fallos = test.fails
    linked1 = LinkedList()
    linked2 = LinkedList()
    for i in range(1000):
        linked1.insertar_en_posicion(i,i)
        linked2.insertar_en_posicion(i,i+1000)
    funciono=True
    try:
        extend(linked1,linked2)
        l=list(range(1000*2))
        actual=linked1.prim
        for i in range(len(l)):
            if actual.v != l[i]: funciono=False
            actual=actual.next    
        test.print_test(s, funciono and check_list_integrity(linked1,linked1.len))
        return valor if (test.fails == fallos) else 0
    except Exception as err:
        error_by_except(s, err)
        return 0