Esempio n. 1
0
def linked_list_test_20():
    s = "Hago varias operaciones (6 inserts uno detras del otro, 1 remove, 1 pop con indice, 2 pop sin indice, un length y un index)"
    value_1 = "Some"
    value_2 = "Body"
    value_3 = "Once"
    try:
        test_list = LinkedList()
        many_insert(test_list, value_1, 2)
        many_insert(test_list, value_2, 2)
        many_insert(test_list, value_3, 2)
        test_list.remove(value_3)
        test_list.pop(1)
        test_list.pop()
        test_element = test_list.pop()

        def custom_test2():
            if not check_list_integrity(test_list, 2):
                return errors["integrity"]
            return ""

        def custom_test():
            return "" if (value_2 == test_element) else errors["assert"]

        result = test_runner(custom_test(), length(test_list, 2),
                             index(test_list, value_2, 1), custom_test2())
        test.print_test(s, result)
    except Exception as err:
        error_by_except(s, err)
Esempio n. 2
0
def linked_list_test_19():
    s = "Hago varias operaciones (4 insert uno detras del otro, 1 pop con indice, 1 pop sin indice y un remove, un length y un index)"
    value_1 = "La orden de los factores"
    value_2 = "No altera el producto"
    try:
        test_list = LinkedList()
        many_insert(test_list, value_1, 2)
        many_insert(test_list, value_2, 1)
        many_insert(test_list, value_1, 1)
        test_list.pop()
        test_list.pop(0)
        test_list.remove(value_1)
        has_thrown_exception = False

        def custom_test2():
            if not check_list_integrity(test_list, 1):
                return errors["integrity"]
            return ""

        def custom_test():
            if test_list.prim.v != value_2:
                return errors["assert"]
            return ""

        result = test_runner(custom_test(), index(test_list),
                             length(test_list, 1), custom_test2())
        test.print_test(s, result)
    except Exception as err:
        error_by_except(s, err)
Esempio n. 3
0
def linked_list_test_48():
    s = "Pruebo hacer un length despues de haber borrado un elemento (pop(0))"
    value_1 = "hue"
    try:
        test_list = LinkedList()
        many_append(test_list, value_1, 9)
        test_list.pop(0)
        test.print_test(s, test_runner(length(test_list, 8)))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 4
0
def linked_list_test_35():
    s = "Pruebo hacer 5000 pop con indice"
    value_1 = "is"
    try:
        test_list = LinkedList()
        many_append(test_list, value_1, 5000)
        for i in range(0, 5000):
            test_list.pop(0)
        test.print_test(s, test_runner(length(test_list, 0)))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 5
0
def linked_list_test_11():
    s = "Pruebo hacer un pop de una lista vacia"
    try:
        test_list = LinkedList()
        error_was_thrown = False
        try:
            test_list.pop()
        except IndexError as err:
            error_was_thrown = True
        test.print_test(s, error_was_thrown)
    except Exception as err:
        error_by_except(s, err)
Esempio n. 6
0
def linked_list_test_12():
    s = "Pruebo hacer demasiados pops"
    try:
        test_list = LinkedList()
        many_append(test_list, "El 8N en la pera", 5)
        error_was_thrown = False
        try:
            for i in range(6):
                test_list.pop()
        except IndexError as err:
            error_was_thrown = True
        test.print_test(s, error_was_thrown)
    except Exception as err:
        error_by_except(s, err)
Esempio n. 7
0
def linked_list_test_26():
    s = "Hago pop del primer elemento de la lista"
    try:
        test_list = LinkedList()
        value_1 = 1
        value_2 = "January"
        value_3 = (1970)
        append(test_list, value_1)
        append(test_list, value_2)
        append(test_list, value_3)
        test_element = test_list.pop(0)

        def custom_test():
            try:
                if check_list_integrity(test_list, 2):
                    return ""
                return errors["integrity"]
            except Exception:
                return errors["integrity"]

        def custom_test2():
            try:
                if check_list_is_correct(
                        test_list.prim, value_2,
                    [value_2, value_3]) and test_element == value_1:
                    return ""
                return errors["assert"]
            except Exception:
                return errors["assert"]

        test.print_test(s, test_runner(custom_test(), custom_test2()))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 8
0
def linked_list_test_13():
    s = "Pruebo hacer un pop valido sin indice"
    value_1 = "El 8N es la fiesta de medios"
    value_2 = "El 8N es la fiesta de gestion"
    try:
        test_list = LinkedList()
        append(test_list, value_1)
        append(test_list, value_2)
        test_value_1 = test_list.pop()
        test_value_3 = test_list.pop()

        def custom_test1():
            try:
                if value_2 == test_value_1 and value_1 == test_value_3:
                    return ""
                return errors["assert"]
            except Exception:
                return errors["assert"]

        def custom_test2():
            try:
                integrity = check_list_integrity(test_list, 0)
                if integrity:
                    return ""
                return errors["integrity"]
            except Exception:
                return errors["integrity"]

        test.print_test(s, test_runner(custom_test1(), custom_test2()))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 9
0
def linked_list_test_14():
    s = "Pruebo hacer un pop valido con indice"
    value_1 = "El 8N es la fiesta de medios"
    value_2 = "El 8N es la fiesta de gestion"
    try:
        test_list = LinkedList()
        append(test_list, "ELEMENTO SORPRESA")
        append(test_list, value_1)
        append(test_list, value_2)
        test_value_1 = test_list.pop(1)
        test_value_2 = test_list.pop(1)
        integrity = check_list_integrity(test_list, 1)
        test.print_test(
            s, value_1 == test_value_1 and value_2 == test_value_2
            and integrity)
    except Exception as err:
        error_by_except(s, err)
Esempio n. 10
0
def linked_list_test_41():
    s = "Hago un pop del ultimo elemento de la lista con indice."
    value_1 = "Esto"
    value_2 = "No esta todo ok"
    try:
        test_list = LinkedList()
        correct_list = []
        for i in range(0, 3):
            append(test_list, value_1)
            append(test_list, value_2)
            correct_list.append(value_1)
            correct_list.append(value_2)

        correct_popped = []
        test_popped = []

        for i in range(0, 3):
            correct_popped.append(correct_list.pop(len(correct_list) - 1))
            current = test_list.prim
            index = 0
            while current is not None:
                current = current.next
                index += 1
            test_popped.append(test_list.pop(index - 1))

        def custom_test():
            if correct_popped == test_popped and check_list_is_correct(
                    test_list.prim, value_1, correct_list):
                return ""
            return errors["assert"]

        def custom_test3():
            if check_list_integrity(test_list, 3):
                return ""
            return errors["integrity"]

        test.print_test(s, test_runner(custom_test(), custom_test3()))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 11
0
def linked_list_test_30():
    s = "Hago pop y append del pop varias veces"
    value_1 = (1, 2, 3)
    value_2 = (4, 5, 6)
    value_3 = (7, 8, 9)
    try:
        test_list = LinkedList()
        for i in range(0, 4):
            test_list.append(value_1)
            test_list.append(value_2)
            test_list.append(value_3)
        for i in range(0, 9):
            temp = test_list.pop()
            test_list.append(temp)

        def custom_test():
            return errors["integrity"] if not check_list_integrity(
                test_list, 12) else ""

        test.print_test(s, test_runner(custom_test()))
    except Exception as err:
        error_by_except(s, err)
Esempio n. 12
0
def linked_list_test_29():
    s = "Hago pop default de una lista con elementos intercalados"
    value_1 = "Foo"
    value_2 = "Bar"
    try:
        test_list = LinkedList()
        for i in range(0, 8):
            append(test_list, value_1)
            append(test_list, value_2)
        result = []
        expected_result = [value_2, value_1, value_2]
        for i in range(0, 3):
            result.append(test_list.pop())

        def custom_test1():
            return errors["assert"] if not (result == expected_result) else ""

        def custom_test2():
            return errors["integrity"] if not check_list_integrity(
                test_list, 13) else ""

        test.print_test(s, test_runner(custom_test2(), custom_test1()))
    except Exception as err:
        error_by_except(s, err)