Example #1
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;
        }