public ComplexNumber scalarProduct(ComplexVector2D v1) { ComplexNumber c; ComplexNumber d; c = this.x.mult(v1.x); d = this.y.mult(v1.y); return (c.add(d)); }
@Test public void shouldAddTwoComplexNumbers() { ComplexNumber number1 = new ComplexNumber(4, 7); ComplexNumber number2 = new ComplexNumber(5, 3); ComplexNumber result = number1.add(number2); assertEquals(9, result.getReal(), 0); assertEquals(10, result.getImaginary(), 0); }
@Test public void multShouldWorkCorrect() { ComplexMatrix2x2 matrix = (ComplexMatrix2x2) context.getBean("zeroMatrix"); ComplexNumber cN = ComplexMatrix2x2Util.getComplexNumber(0, 0); when(cN.add(any(ComplexNumber.class))).thenReturn(cN); when(cN.mult(any(ComplexNumber.class))).thenReturn(cN); ComplexNumber[][] complexNumbers = new ComplexNumber[][] {{cN, cN}, {cN, cN}}; assertTrue(Arrays.deepEquals(matrix.mult(matrix).getMatrix(), complexNumbers)); }