コード例 #1
0
def test_duplicates():
    c = Complex(2, 2)
    assert (BLL.lists.IO.in_list([], c) == False)
    myList = convert_list([1, 2 + 2j, 3])
    assert (BLL.lists.IO.in_list(myList, Complex(0, 4)) == False)
    myList = convert_list([1, 2 + 2j, 3])
    assert (BLL.lists.IO.in_list(myList, Complex(2, 2)) == True)
コード例 #2
0
def test_det_prod():
    myList = []
    results = BLL.lists.operations.det_prod(myList, 0, 0)
    assert (Complex.isEqual(results, Complex(0, 0)))

    myList = convert_list([1 + 2j, 3 + 5j, 20 + 3j, 3 + 4j])
    results = BLL.lists.operations.det_prod(myList, 1, 3)
    prod = (1 + 2j) * (3 + 5j) * (20 + 3j)
    correct = Complex(prod.real, prod.imag)
    assert (Complex.isEqual(results, correct))
コード例 #3
0
def test_add_number():
    myList = convert_list([1j, 2, 4 - 5j])
    try:
        results = BLL.lists.IO.add_number(myList, Complex(10, 2))
        correct = convert_list([1j, 2, 4 - 5j, 10 + 2j])
        assert (BLL.lists.operations.isEqual(results, correct))
    except Exception as ex:
        assert (False)

    try:
        results = BLL.lists.IO.add_number(myList, Complex(4, -5))
        assert (False)
    except Exception as ex:
        assert (True)
コード例 #4
0
def det_prod(myList, start, end):
    """
    Determina produsul elementelor din myList aflate in secventa [start, end]
    :param myList: lista de numere complexe
    :param start: pozitia initiala
    :param end: pozitia finala
    :return suma: produsul elementelor din [start, end] (0 - valoare implicita) (obiect Complex)
    """
    if len(myList) == 0:
        return Complex(0, 0)

    prod = myList[start - 1].copy_complex()
    for i in range(start, end):
        prod = Complex.times(prod, myList[i])

    return prod
コード例 #5
0
def isEqual(list1, list2):
    """Returneaza true daca cele doua liste sunt egale
    :param list1: lista de obiecte Complex
    :param list2: lista de obiecte Complex
    :return True: daca cele doua liste sunt egale"""
    if len(list1) != len(list2):
        return False
    for i in range(0, len(list1)):
        if not Complex.isEqual(list1[i], list2[i]):
            return False
    return True
コード例 #6
0
def convert_list(testList):
    """
    Converteste o lista de numere complexe intr-o lista de obiecte Complex
    :param testList: lista de numere complexe
    :return complexList: lista de obiecte Complex
    """
    complexList = []
    for nr in testList:
        compl = Complex(nr.real, nr.imag)
        complexList.append(compl)
    return complexList
コード例 #7
0
def add_command(complexOp, args=None):
    try:
        number = complex(args)
    except ValueError:
        print("Argument invalid\n")
    else:
        compl = Complex(number.real, number.imag)
        myList = complexOp.get_complexList()
        myList = BLL.lists.IO.add_number(myList, compl)
        complexOp.set_complexList(myList)
        ui.console.print_seq_complex(myList, 0, len(myList),
                                     "Lista rezultata: \n")
コード例 #8
0
def test_insert_number():
    myList = []
    try:
        results = BLL.lists.IO.insert_number(myList, Complex(0, 2), 1)
        correct = convert_list([2j])
        assert (BLL.lists.operations.isEqual(results, correct))
    except Exception as ex:
        assert (False)

    myList = convert_list([-2, -2j, 3, 4j])
    try:
        results = BLL.lists.IO.insert_number(myList, Complex(0, 2), 2)
        correct = convert_list([-2, 2j, -2j, 3, 4j])
        assert (BLL.lists.operations.isEqual(results, correct))
    except Exception as ex:
        assert (False)

    myList = convert_list([-2, -2j, 3, 4j])
    try:
        results = BLL.lists.IO.insert_number(myList, Complex(0, -2), 2)
        assert (False)
    except Exception as ex:
        assert (True)
コード例 #9
0
ファイル: console.py プロジェクト: RaulPele/LAB4-6
def get_Complex(inputMsg=None):
    """
    Returneaza un obiect de tip Complex continand numarul dat de utilizator
    :return number: obiectul Complex format
    """
    print(
        "Numarul complex este de tipul a+bj (a- numar real numit parte reala, b- numar real numit"
        + " coeficient imaginar)\n")
    if inputMsg is not None:
        print(inputMsg)

    real = __get_number(float, "Dati partea reala a numarului (a): ")
    imag = __get_number(float, "Dati coeficientul imaginar a numarului (b): ")

    return Complex(real, imag)
コード例 #10
0
def det_sum(myList, start, end):
    """
    Determina suma elementelor din myList aflate in secventa [start, end]
    :param myList: lista de numere complexe
    :param start: pozitia initiala
    :param end: pozitia finala
    :return suma: suma elementelor din [start, end] (0 - valoare implicita)
    """

    sumaR = 0
    sumaI = 0
    for i in range(start - 1, end):
        sumaR += myList[i].get_real()
        sumaI += myList[i].get_imag()
    return Complex(sumaR, sumaI)
コード例 #11
0
def test_replace_number():
    try:
        number = Complex(1)
        results = BLL.lists.IO.replace_number([], number, Complex(2))
        assert (False)
    except Exception as ex:
        assert (str(ex) == "Numarul " + number.get_complex_string() +
                " nu se afla in lista!")

    try:
        number = Complex(1, 2)
        myList = convert_list([1 + 2j, -1 - 2j, 0, 1 + 2j, 100 + 100j])
        results = BLL.lists.IO.replace_number(myList, number, Complex(0, 0))
        correct = convert_list([0, -1 - 2j, 0, 0, 100 + 100j])
        assert (BLL.lists.operations.isEqual(results, correct))
    except Exception as ex:
        assert (False)
コード例 #12
0
def test_det_sum():
    result = BLL.lists.operations.det_sum([], 1, 0)
    correct = Complex(0, 0)
    assert (Complex.isEqual(result, correct))

    myList = convert_list([1 + 1j, 2 + 2j, 3, 4j])
    result = BLL.lists.operations.det_sum(myList, 1, 4)
    correct = Complex(6, 7)
    assert (Complex.isEqual(result, correct))

    myList = convert_list([-1, -5 + 3j, 3 - 5j])
    result = BLL.lists.operations.det_sum(myList, 1, 2)
    correct = Complex(-6, 3)
    assert (Complex.isEqual(result, correct))
コード例 #13
0
def imag_convert(list):
    for i in range(0, len(list)):
        b = Complex()
        b.set_imag(list[i].get_imag())
        list[i] = b