Example #1
0
        /// <summary>
        /// Verifies that two objects are equal.  Two objects are considered
        /// equal if both are null, or if both have the same value.  All
        /// non-numeric types are compared by using the <c>Equals</c> method.
        /// Arrays are compared by comparing each element using the same rules.
        /// If they are not equal an <see cref="AssertionException"/> is thrown.
        /// </summary>
        /// <param name="expected">The value that is expected</param>
        /// <param name="actual">The actual value</param>
        /// <param name="message">The message to display if objects are not equal</param>
        /// <param name="args">Arguments to be used in formatting the message</param>
        static public void AreEqual(Object expected, Object actual, string message, params object[] args)
        {
            if (expected == null && actual == null)
            {
                return;
            }
            if (expected == null || actual == null)
            {
                Assert.FailNotEquals(expected, actual, message, args);
            }

            // FOr now, dynamically call array assertion if necessary. Try to move
            // this into the ObjectsEqual method later on.
            if (expected.GetType().IsArray&& actual.GetType().IsArray)
            {
                Assert.AreEqual((System.Array)expected, (System.Array)actual, message, args);
            }
            else
            {
                ++counter;

                if (!ObjectsEqual(expected, actual))
                {
                    Assert.FailNotEquals(expected, actual, message, args);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Verifies that two ints are equal. If
 /// they are not equals then an <see cref="AssertionException"/> is
 /// thrown.
 /// </summary>
 /// <param name="expected">The expected value</param>
 /// <param name="actual">The actual value</param>
 /// <param name="message">The message printed out upon failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 static public void AreEqual(int expected, int actual, string message, params object[] args)
 {
     ++counter;
     if (!(expected == actual))
     {
         Assert.FailNotEquals(expected, actual, message, args);
     }
 }
Example #3
0
 /// <summary>
 /// Verifies that two floats are equal considering a delta. If the
 /// expected value is infinity then the delta value is ignored. If
 /// they are not equals then an <see cref="AssertionException"/> is
 /// thrown.
 /// </summary>
 /// <param name="expected">The expected value</param>
 /// <param name="actual">The actual value</param>
 /// <param name="delta">The maximum acceptable difference between the
 /// the expected and the actual</param>
 /// <param name="message">The message printed out upon failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 static public void AreEqual(float expected,
                             float actual, float delta, string message, params object[] args)
 {
     ++counter;
     // handle infinity specially since subtracting two infinite values gives
     // NaN and the following test fails. mono also needs NaN to be handled
     // specially although ms.net could use either method.
     if (float.IsInfinity(expected) || float.IsNaN(expected) || float.IsNaN(actual))
     {
         if (!(expected == actual))
         {
             Assert.FailNotEquals(expected, actual, message, args);
         }
     }
     else if (!(Math.Abs(expected - actual) <= delta))
     {
         Assert.FailNotEquals(expected, actual, message, args);
     }
 }
Example #4
0
        /// <summary>
        /// Verifies that two arrays are equal. If they are not,
        /// then an <see cref="AssertionException"/> is thrown.
        /// </summary>
        /// <param name="expected">The expected value</param>
        /// <param name="actual">The actual value</param>
        /// <param name="message">The message printed out upon failure</param>
        /// <param name="args">Arguments to be used in formatting the message</param>
        static public void AreEqual(System.Array expected, System.Array actual, string message, params object[] args)
        {
            ++counter;

            if (expected == null && actual == null)
            {
                return;
            }

            if (expected == null || actual == null)
            {
                Assert.FailNotEquals(expected, actual, message, args);
            }

            if (expected.Rank != actual.Rank)
            {
                Assert.FailNotEquals(expected, actual, message, args);
            }

            if (expected.Rank != 1)
            {
                Assert.Fail("Multi-dimension array comparison is not supported");
            }

            int iLength = Math.Min(expected.Length, actual.Length);

            for (int i = 0; i < iLength; i++)
            {
                if (!ObjectsEqual(expected.GetValue(i), actual.GetValue(i)))
                {
                    Assert.FailArraysNotEqual(i, expected, actual, message, args);
                }
            }

            if (expected.Length != actual.Length)
            {
                Assert.FailArraysNotEqual(iLength, expected, actual, message, args);
            }

            return;
        }