public void testScalarMultiplyInf() { Complex z = new Complex(1, 1); Complex w = z.multiply(Double.POSITIVE_INFINITY); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); w = z.multiply(Double.NEGATIVE_INFINITY); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); }
public void testDivideNaNInf() { Complex z = oneInf.divide(Complex.ONE); assertTrue(Double.isNaN(z.getReal())); assertEquals(inf, z.getImaginary(), 0); z = negInfNegInf.divide(oneNaN); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); z = negInfInf.divide(Complex.ONE); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); }
public void testAdd() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.add(y); assertEquals(8.0, z.getReal(), 1.0e-5); assertEquals(10.0, z.getImaginary(), 1.0e-5); }
public void testSubtract() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.subtract(y); assertEquals(-2.0, z.getReal(), 1.0e-5); assertEquals(-2.0, z.getImaginary(), 1.0e-5); }
public void testScalarMultiply() { Complex x = new Complex(3.0, 4.0); double y = 2.0; Complex z = x.multiply(y); assertEquals(6.0, z.getReal(), 1.0e-5); assertEquals(8.0, z.getImaginary(), 1.0e-5); }
public void testMultiply() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.multiply(y); assertEquals(-9.0, z.getReal(), 1.0e-5); assertEquals(38.0, z.getImaginary(), 1.0e-5); }
public void testDivide() { Complex x = new Complex(3.0, 4.0); Complex y = new Complex(5.0, 6.0); Complex z = x.divide(y); assertEquals(39.0 / 61.0, z.getReal(), 1.0e-5); assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5); }
public void testAddNaN() { Complex x = new Complex(3.0, 4.0); Complex z = x.add(Complex.NaN); assertTrue(z.isNaN()); z = new Complex(1, nan); Complex w = x.add(z); assertEquals(w.getReal(), 4.0, 0); assertTrue(Double.isNaN(w.getImaginary())); }
public void testMultiplyNaNInf() { Complex z = new Complex(1, 1); Complex w = z.multiply(infOne); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); // [MATH-164] assertTrue(new Complex(1, 0).multiply(infInf).equals(Complex.INF)); assertTrue(new Complex(-1, 0).multiply(infInf).equals(Complex.INF)); assertTrue(new Complex(1, 0).multiply(negInfZero).equals(Complex.INF)); w = oneInf.multiply(oneNegInf); assertEquals(w.getReal(), inf, 0); assertEquals(w.getImaginary(), inf, 0); w = negInfNegInf.multiply(oneNaN); assertTrue(Double.isNaN(w.getReal())); assertTrue(Double.isNaN(w.getImaginary())); }
public void testDivideInfinite() { Complex x = new Complex(3, 4); Complex w = new Complex(neginf, inf); assertTrue(x.divide(w).equals(Complex.ZERO)); Complex z = w.divide(x); assertTrue(Double.isNaN(z.getReal())); assertEquals(inf, z.getImaginary(), 0); w = new Complex(inf, inf); z = w.divide(x); assertTrue(Double.isNaN(z.getImaginary())); assertEquals(inf, z.getReal(), 0); w = new Complex(1, inf); z = w.divide(w); assertTrue(Double.isNaN(z.getReal())); assertTrue(Double.isNaN(z.getImaginary())); }
public void testAddInfinite() { Complex x = new Complex(1, 1); Complex z = new Complex(inf, 0); Complex w = x.add(z); assertEquals(w.getImaginary(), 1, 0); assertEquals(inf, w.getReal(), 0); x = new Complex(neginf, 0); assertTrue(Double.isNaN(x.add(z).getReal())); }
private static boolean closeFourDigit(Complex a, Complex b) { return closeFourDigit(a.getReal(), b.getReal()) && closeFourDigit(a.getImaginary(), b.getImaginary()); }
public void evaluateAt(Complex var, Complex res) { res.setValue(var.getImaginary(), var.getReal()); }
public TestComplex(Complex other) { this(other.getReal(), other.getImaginary()); }
public void testConstructor() { Complex z = new Complex(3.0, 4.0); assertEquals(3.0, z.getReal(), 1.0e-5); assertEquals(4.0, z.getImaginary(), 1.0e-5); }
public void testNegate() { Complex x = new Complex(3.0, 4.0); Complex z = x.negate(); assertEquals(-3.0, z.getReal(), 1.0e-5); assertEquals(-4.0, z.getImaginary(), 1.0e-5); }