public static void AlmostEqual(Complex expected, Complex actual) { if (expected.IsNaN() && actual.IsNaN() || expected.IsInfinity() && expected.IsInfinity()) { return; } if (!expected.Real.AlmostEqual(actual.Real)) { Assert.Fail("Real components are not equal. Expected:{0}; Actual:{1}", expected.Real, actual.Real); } if (!expected.Imaginary.AlmostEqual(actual.Imaginary)) { Assert.Fail("Imaginary components are not equal. Expected:{0}; Actual:{1}", expected.Imaginary, actual.Imaginary); } }
public void CanDetermineIfInfinity() { var complex = new Complex(double.PositiveInfinity, 1); Assert.IsTrue(complex.IsInfinity(), "Real part is infinity."); complex = new Complex(1, double.NegativeInfinity); Assert.IsTrue(complex.IsInfinity(), "Imaginary part is infinity."); complex = new Complex(double.NegativeInfinity, double.PositiveInfinity); Assert.IsTrue(complex.IsInfinity(), "Both parts are infinity."); }