Exemple #1
0
def testInitializeList():
    lst = [None] * 10
    initializeList(lst)
    aux = [{
        'integer_part': 1,
        'complex_part': 6
    }, {
        'integer_part': 9,
        'complex_part': 1
    }, {
        'integer_part': 2,
        'complex_part': 0
    }, {
        'integer_part': 2,
        'complex_part': 5
    }, {
        'integer_part': 1,
        'complex_part': 6
    }, {
        'integer_part': 0,
        'complex_part': 4
    }, {
        'integer_part': 2,
        'complex_part': 0
    }, {
        'integer_part': 1,
        'complex_part': 6
    }, {
        'integer_part': 3,
        'complex_part': 5
    }, {
        'integer_part': 2,
        'complex_part': 1
    }]
    assert (lst == aux)
def uiMenu():
    '''
        Print a menu for user and call functions
    '''
    command_type = {
        "1": menuAddNumber,
        "2": menuInsertNumber,
        "3": menuRemoveNumber,
        "4": menuReplaceNumber,
        "5": menuListNumbers,
        "6": menuSumNumbers,
        "7": menuProductNumbers
    }
    lst = [None] * 10
    initializeList(lst)
    while True:
        printMenu()
        cmd = input("Input your command in lower-case: ")
        if cmd == "8":
            break
        if cmd not in command_type:
            print("Command not known")
        else:
            command_type[cmd](lst)
            print("Command processed!")
Exemple #3
0
def testListRealNumber():
    lst = [None] * 10
    initializeList(lst)
    assert (listRealNumbers(lst, 0, 8) == [{
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 0,
        'integer_part': 2
    }])
Exemple #4
0
def testFilterRealNumbers():
    lst = [None] * 10
    initializeList(lst)
    lst = filterRealNumbers(lst)
    assert (lst == [{
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 0,
        'integer_part': 2
    }])
Exemple #5
0
def testListModuloNumber():
    lst = [None] * 10
    initializeList(lst)
    assert (listModuloNumbers(lst, "<", 5) == [{
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 4,
        'integer_part': 0
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 1,
        'integer_part': 2
    }])
Exemple #6
0
def testFilterModuloNumbers():
    lst = [None] * 10
    initializeList(lst)
    lst = filterModuloNumbers(lst, "<", 5)
    assert (lst == [{
        'integer_part': 2,
        'complex_part': 0
    }, {
        'integer_part': 0,
        'complex_part': 4
    }, {
        'integer_part': 2,
        'complex_part': 0
    }, {
        'integer_part': 2,
        'complex_part': 1
    }])
def readCommands():
    '''
        Checks if inputed commands exists and execute a specific function. It stays in the loop until 'exit' is input.
        
        output data:
        according to commands
    '''
    lst = [None] * 10
    initializeList(lst)
    lstBackUp = []
    lstBackUp = lstBackUp + [lst[:]]
    command_type = {
        "add": uiAddNumber,
        "insert": uiInsertNumber,
        "replace": uiReplaceNumber,
        "remove": uiRemoveNumber,
        "sum": uiSumNumbers,
        "product": uiProductNumbers,
        "list": uiListNumbers,
        "filter": uiFilterNumbers
    }
    while True:
        cmd, args = getCommand()
        if cmd == "exit":
            return
        if cmd == "undo":
            lst, lstBackUp = uiUndoCommand(lst, args, lstBackUp)
        else:
            if cmd in command_type:
                if checkArgs(cmd, args) == True:
                    command_type[cmd](lst, args)
                    if cmd != "sum" and cmd != "product" and cmd != "list":
                        lstBackUp = lstBackUp + [lst[:]]
                else:
                    print("Try inputing the arguments correctly")
            else:
                print("Command not known")
Exemple #8
0
def testUndoCommand():
    lst = [None] * 10
    initializeList(lst)
    lst = filterRealNumbers(lst)
    lstBackUp = [[{
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 1,
        'integer_part': 9
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 5,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 4,
        'integer_part': 0
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 5,
        'integer_part': 3
    }, {
        'complex_part': 1,
        'integer_part': 2
    }],
                 [{
                     'complex_part': 0,
                     'integer_part': 2
                 }, {
                     'complex_part': 0,
                     'integer_part': 2
                 }]]
    lst, lstBackUp = undoCommand(lstBackUp)
    assert (lst == [{
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 1,
        'integer_part': 9
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 5,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 4,
        'integer_part': 0
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 5,
        'integer_part': 3
    }, {
        'complex_part': 1,
        'integer_part': 2
    }])
    assert (lstBackUp == [[{
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 1,
        'integer_part': 9
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 5,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 4,
        'integer_part': 0
    }, {
        'complex_part': 0,
        'integer_part': 2
    }, {
        'complex_part': 6,
        'integer_part': 1
    }, {
        'complex_part': 5,
        'integer_part': 3
    }, {
        'complex_part': 1,
        'integer_part': 2
    }]])