def menu(self):
     while True:
         ConsoleUI.printMenu()
         op = read_input()
         fout = open("C://Users/SergiuP/eclipse-workspace/Lab8/DataOut.txt",
                     "w")
         fout.close()
         if (op == 0):
             exit()
         elif (op == 1):
             print("Give the real and imaginary part of the complex number")
             real = read_input()
             imag = read_input()
             try:
                 self.__ctrl.CreateNumber(real, imag)
             except ValueError:
                 print("Give numbers please")
         elif (op == 2):
             print("Give index")
             index = read_input()
             self.__ctrl.DelIndex(index)
         elif (op == 3):
             self.__ctrl.PrintAll()
         elif (op == 4):
             self.__ctrl.Clear()
         elif (op == 5):
             self.__ctrl.CartesianForm()
         elif (op == 6):
             self.__ctrl.PolarForm()
         elif (op == 7):
             self.__ctrl.Conjugate()
         elif (op == 8):
             print("Give a number")
             real = read_input()
             self.__ctrl.MultiplyReal(real)
         elif (op == 9):
             print("Give a number")
             imag = read_input()
             self.__ctrl.MultiplyImaginary(imag)
         elif (op == 10):
             print("Give the real and imaginary part of the complex number")
             real = read_input()
             imag = read_input()
             self.__ctrl.AddComplex(Complex(real, imag))
         elif (op == 11):
             print("Give the real and imaginary part of the complex number")
             real = read_input()
             imag = read_input()
             self.__ctrl.MultiplyComplex(Complex(real, imag))
         elif (op == 12):
             self.__ctrl.Matrix()
         elif (op == 13):
             print("Give power")
             power = read_input()
             self.__ctrl.Power(power)
         elif (op == 14):
             self.__ctrl.SquareR()
         elif (op == 15):
             self.__ctrl.Exponential()
 def test_delAll(self):
     s = Repository()
     c = Complex(3, 2)
     c1 = Complex(4, 5)
     c2 = Complex(-1, 3)
     s.addComplex(c)
     s.addComplex(c1)
     s.addComplex(c2)
     s.delAll()
     self.assertEqual(s.getLength(), 0)
 def test_addComplex(self):
     s = Repository()
     c = Complex(3, 4)
     s.addComplex(c)
     self.assertEqual(s.getLength(), 1)
     s = Repository()
     c = Complex(4)
     s.addComplex(c)
     self.assertEqual(s.getLength(), 1)
     s = Repository()
     c = Complex()
     s.addComplex(c)
     self.assertEqual(s.getLength(), 1)
 def test_delIndex(self):
     s = Repository()
     c = Complex(3, 2)
     c1 = Complex(4, 5)
     c2 = Complex(-1, 3)
     s.addComplex(c)
     s.addComplex(c1)
     s.addComplex(c2)
     s.delIndex(0)
     self.assertEqual(s.getLength(), 2)
     try:
         s.delIndex(5)
     except IndexError:
         assert True
 def CreateNumber(self,real=0,imag=0):
     ''' Descr: Creates a complex number and adds it to the list
         Data: real,imag
         Preconditions:  real and imag are both integer numbers
         Result: 
         Postcondition: 
     '''
     c=Complex(real,imag)
     self.__repo.addComplex(c)
 def test_setReal(self):
     p=Complex(3,4)
     p.setReal(4)
     self.assertEqual(p.getReal(),4)
     p=Complex(3,4)
     p.setReal(0)
     self.assertEqual(p.getReal(),0)
     p=Complex(3,4)
     p.setReal(-5)
     self.assertEqual(p.getReal(),-5)
     p=Complex(3,4)
     p.setReal(13)
     self.assertEqual(p.getReal(),13)
     p=Complex(3,4)
     p.setReal(-9)
     self.assertEqual(p.getReal(),-9)
 def test_ExponentialOfComplex(self):
     c=Complex(3,4)
     self.assertAlmostEqual(c.ExponentialOfComplex().getReal(),-13,0)
     self.assertAlmostEqual(c.ExponentialOfComplex().getImaginary(),-15,0)
 def test_SquareRootOfComplex(self):
     c=Complex(3,4)
     self.assertEqual(c.SquareRootOfComplex().getReal(),2)
     self.assertEqual(c.SquareRootOfComplex().getImaginary(),1)
 def test_getImaginary(self):
     p=Complex(3,4)
     self.assertEqual(p.getImaginary(),4)
     p=Complex(5)
     self.assertEqual(p.getImaginary(),0)
     p=Complex()
     self.assertEqual(p.getImaginary(),0)
     p=Complex(0,0)
     self.assertEqual(p.getImaginary(),0)
     p=Complex(5,0)
     self.assertEqual(p.getImaginary(),0)
 def test_PowerOfComplex(self):
     c=Complex(3,4)
     self.assertEqual(c.PowerOfComplex(3).getReal(),-117)
     self.assertEqual(c.PowerOfComplex(3).getImaginary(),44)
     c=Complex(2,2)
     self.assertEqual(c.PowerOfComplex(3).getReal(),-16)
     self.assertEqual(c.PowerOfComplex(3).getImaginary(),16)
     c=Complex(2,0)
     self.assertEqual(c.PowerOfComplex(3).getReal(),8)
     self.assertEqual(c.PowerOfComplex(3).getImaginary(),0)
     c=Complex(0,2)
     self.assertEqual(c.PowerOfComplex(3).getReal(),0)
     self.assertEqual(c.PowerOfComplex(3).getImaginary(),-8)
     c=Complex(2,0)
     try:
         self.assertEqual(c.PowerOfComplex(-3).getReal(),0)
         self.assertEqual(c.PowerOfComplex(-3).getImaginary(),-8)
     except ValueError:
         assert True
 def test_getArgument(self):
     p=Complex(3,4)
     self.assertAlmostEqual(p.getArgument(),math.atan(4/3),10)
     p=Complex(5)
     self.assertEqual(p.getArgument(),0)
     p=Complex()
     self.assertEqual(p.getArgument(),0)
     p=Complex(0,0)
     self.assertEqual(p.getArgument(),0)
     p=Complex(4,3)
     self.assertAlmostEqual(p.getArgument(),math.atan(3/4),10)
 def test_AddTwoComplexNumbers(self):
     p=Complex(3,2)
     o=Complex(2,3)
     r=Complex(5,5)
     self.assertEqual(p.AddTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.AddTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(0,2)
     o=Complex(2,3)
     r=Complex(2,5)
     self.assertEqual(p.AddTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.AddTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(0,2)
     o=Complex(2,0)
     r=Complex(2,2)
     self.assertEqual(p.AddTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.AddTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex()
     o=Complex()
     r=Complex()
     self.assertEqual(p.AddTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.AddTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(2)
     o=Complex(3)
     r=Complex(5)
     self.assertEqual(p.AddTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.AddTwoComplexNumbers(o).getImaginary(), r.getImaginary())
 def test_MultiplyByImaginary(self):
     p=Complex(3,4)
     q=Complex(-16,12)
     self.assertEqual(p.MultiplyByImaginary(4).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByImaginary(4).getImaginary(),q.getImaginary())
     p=Complex(2,-4)
     q=Complex(-8,-4)
     self.assertEqual(p.MultiplyByImaginary(-2).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByImaginary(-2).getImaginary(),q.getImaginary())
     p=Complex()
     q=Complex()
     self.assertEqual(p.MultiplyByImaginary(7).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByImaginary(7).getImaginary(),q.getImaginary())
     p=Complex(5,0)
     q=Complex(0,10)
     self.assertEqual(p.MultiplyByImaginary(2).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByImaginary(2).getImaginary(),q.getImaginary())
     p=Complex(-3)
     q=Complex(0,-6)
     self.assertEqual(p.MultiplyByImaginary(2).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByImaginary(2).getImaginary(),q.getImaginary())
 def test_MultiplyByReal(self):
     p=Complex(3,4)
     q=Complex(6,8)
     self.assertEqual(p.MultiplyByReal(2).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByReal(2).getImaginary(),q.getImaginary())
     p=Complex(2,-4)
     q=Complex(-2,4)
     self.assertEqual(p.MultiplyByReal(-1).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByReal(-1).getImaginary(),q.getImaginary())
     p=Complex()
     q=Complex()
     self.assertEqual(p.MultiplyByReal(7).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByReal(7).getImaginary(),q.getImaginary())
     p=Complex(5,0)
     q=Complex(0,0)
     self.assertEqual(p.MultiplyByReal(0).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByReal(0).getImaginary(),q.getImaginary())
     p=Complex(-3)
     q=Complex(-3)
     self.assertEqual(p.MultiplyByReal(1).getReal(),q.getReal())
     self.assertEqual(p.MultiplyByReal(1).getImaginary(),q.getImaginary())
 def test_getReal(self):
     p=Complex(3,4)
     self.assertEqual(p.getReal(),3)
     p=Complex(5)
     self.assertEqual(p.getReal(),5)
     p=Complex()
     self.assertEqual(p.getReal(),0)
     p=Complex(0,0)
     self.assertEqual(p.getReal(),0)
     p=Complex(5,0)
     self.assertEqual(p.getReal(),5)
 def test_setImaginary(self):
     p=Complex(3,4)
     p.setImaginary(5)
     self.assertEqual(p.getImaginary(),5)
     p=Complex(3,4)
     p.setImaginary(0)
     self.assertEqual(p.getImaginary(),0)
     p=Complex(3,4)
     p.setImaginary(-5)
     self.assertEqual(p.getImaginary(),-5)
     p=Complex(3,4)
     p.setImaginary(13)
     self.assertEqual(p.getImaginary(),13)
     p=Complex(3,4)
     p.setImaginary(-9)
     self.assertEqual(p.getImaginary(),-9)
 def test_getModulus(self):
     p=Complex(3,4)
     self.assertEqual(p.getModulus(),5)
     p=Complex(5)
     self.assertEqual(p.getModulus(),5)
     p=Complex()
     self.assertEqual(p.getModulus(),0)
     p=Complex(0,0)
     self.assertEqual(p.getModulus(),0)
     p=Complex(-25,4)
     self.assertEqual(p.getModulus(),math.sqrt(641))
 def test_MultiplyTwoComplexNumbers(self):
     p=Complex(3,2)
     o=Complex(2,3)
     r=Complex(0,13)
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(0,2)
     o=Complex(2,3)
     r=Complex(-6,4)
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(0,2)
     o=Complex(2,0)
     r=Complex(0,4)
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex()
     o=Complex()
     r=Complex()
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getImaginary(), r.getImaginary())
     p=Complex(2)
     o=Complex(3)
     r=Complex(6,0)
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getReal(),r.getReal())
     self.assertEqual(p.MultiplyTwoComplexNumbers(o).getImaginary(), r.getImaginary())
 def test_getConjugate(self):
     p=Complex(3,4)
     q=Complex(3,-4)
     self.assertEqual(p.getConjugate().getImaginary(),q.getImaginary())
     p=Complex(2,-4)
     q=Complex(2,4)
     self.assertEqual(p.getConjugate().getImaginary(),q.getImaginary())
     p=Complex()
     q=Complex()
     self.assertEqual(p.getConjugate().getImaginary(),q.getImaginary())
     p=Complex(5,0)
     q=Complex(5,0)
     self.assertEqual(p.getConjugate().getImaginary(),q.getImaginary())
     p=Complex(-3)
     q=Complex(-3)
     self.assertEqual(p.getConjugate().getImaginary(),q.getImaginary())
 def test_MatrixRepresentation(self):
     c=Complex(3,4)
     self.assertEqual(c.MatrixRepresentation(),[[3,-4],[4,3]])
     c=Complex(-3,-4)
     self.assertEqual(c.MatrixRepresentation(),[[-3,4],[-4,-3]])
     c=Complex(4)
     self.assertEqual(c.MatrixRepresentation(),[[4,0],[0,4]])
     c=Complex(0,3)
     self.assertEqual(c.MatrixRepresentation(),[[0,-3],[3,0]])
     c=Complex(0,0)
     self.assertEqual(c.MatrixRepresentation(),[[0,0],[0,0]])