Пример #1
0
        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);
            }
        }
Пример #2
0
 public void CanDetermineIfNaN()
 {
     var complex = new Complex(double.NaN, 1);
     Assert.IsTrue(complex.IsNaN(), "Real part is NaN.");
     complex = new Complex(1, double.NaN);
     Assert.IsTrue(complex.IsNaN(), "Imaginary part is NaN.");
     complex = new Complex(double.NaN, double.NaN);
     Assert.IsTrue(complex.IsNaN(), "Both parts are NaN.");
 }