def testCreateComplexNumber(): complexNumber = createComplexNumber(34, 87) assert getReal(complexNumber) == 34 assert getImaginary(complexNumber) == 87 setReal(complexNumber, 100) assert getReal(complexNumber) == 100 setImaginary(complexNumber, -98) assert getImaginary(complexNumber) == -98
def testServiceRemoveTo(): l = [[0,0], [10,10], [20,20], [30,30], [40,40]] serviceRemoveTo(l, 2, 4) assert len(l) == 2 assert getReal(l[0]) == 0 assert getImaginary(l[0]) == 0 assert getReal(l[1]) == 10 assert getImaginary(l[1]) == 10 try: serviceRemoveTo(l, "2sX5", 34) assert False except Exception as ex: assert (str(ex) == "Invalid position!\n")
def testServiceReplaceWith(): l = [[0,0], [10,10], [20,20], [30,30], [40,40]] serviceReplaceWith(l, 10, 10, 11, 12) assert getReal(l[1]) == 11 assert getImaginary(l[1]) == 12 try: serviceReplaceWith(l, "12,2", "das", "d32", "e222") assert False except Exception as ex: assert str(ex) == "Invalid real part!\nInvalid imaginary part!\n"
def testServiceRemoveSimple(): l = [[0,0], [10,10], [20,20], [30,30], [40,40]] serviceRemoveSimple(l, 2) assert len(l) == 4 assert getReal(l[2]) == 30 assert getImaginary(l[2]) == 30 try: serviceRemoveSimple(l, "2.5") assert False except Exception as ex: assert (str(ex) == "Invalid position!\n")
def testServiceInsertAt(): l = [[0,0], [10,10], [20,20], [30,30], [40,40]] serviceInsertAt(l, 34, 87, 2) assert len(l) == 6 assert getReal(l[2]) == 34 assert getImaginary(l[2]) == 87 try: serviceInsertAt(l, "34.56", "87asd.56", 2) assert False except Exception as ex: assert (str(ex) == "Invalid real part!\nInvalid imaginary part!\n")
def testServiceAddComplexNumber(): l = [] serviceAddComplexNumber(l, 34, 87) assert len(l) == 1 assert getReal(l[0]) == 34 assert getImaginary(l[0]) == 87 try: serviceAddComplexNumber(l, "34.56", "87as.56") assert False except Exception as ex: assert (str(ex) == "Invalid real part!\nInvalid imaginary part!\n")
def validateComplexNumber(complexNumber): ''' Function that validates the real and the imaginary part of a complex number\ input: complexNumber - a complex number output: - ; if the real and the imaginary parts are valid raises: Exception if the real part is not an integer number "invalid real part!" if the imaginary is not an integer number "invalid imaginary part!" errors = "" if type(getReal(complexNumber)) != int: errors = errors + "Invalid real part!\n" if type(getImaginary(complexNumber)) != int: errors = errors + "Invalid imaginary part!\n" if len(errors) > 0: raise Exception(errors) ''' errors = "" if checkIsNumber(getReal(complexNumber)) == False: errors = errors + "Invalid real part!\n" if checkIsNumber(getImaginary(complexNumber)) == False: errors = errors + "Invalid imaginary part!\n" if len(errors) > 0: raise Exception(errors)
def testReplaceWith(): l = [[0,0], [10,10], [20,20], [30,30], [40,40]] featureReplaceWith(l, [10,10], [11,12]) assert getReal(l[1]) == 11 assert getImaginary(l[1]) == 12