public static void HaveEqualParts <T>(
            IndexPartition <T> expected,
            IndexPartition <T> actual)
        {
            if (null == expected && null == actual)
            {
                return;
            }

            if (((null == expected) && (null != actual))
                ||
                ((null != expected) && (null == actual)))
            {
                throw new AssertFailedException(
                          "One IndexPartition instance is null, the other is not.");
            }

            int expectedCount = expected.Count;
            int actualCount   = actual.Count;

            if (expectedCount != actualCount)
            {
                throw new AssertFailedException(
                          "IndexPartition instances have not the same number of parts.");
            }

            List <T> availableIds = new(actual.Identifiers);

            for (int i = 0; i < expected.Count; i++)
            {
                bool expectedPartIsMissing = true;
                var  expectedPart          = expected[expected.Identifiers[i]];
                for (int j = 0; j < availableIds.Count; j++)
                {
                    var actualPart = actual[availableIds[j]];
                    try
                    {
                        IndexCollectionAssert.AreEqual(
                            expectedPart, actualPart);
                        expectedPartIsMissing = false;
                        availableIds.RemoveAt(j);
                        break;
                    }
                    catch (AssertFailedException)
                    {
                    }
                }
                if (expectedPartIsMissing)
                {
                    throw new AssertFailedException(
                              msg: string.Format(
                                  "Missing expected part {0}.",
                                  expectedPart));
                }
            }
        }
Example #2
0
 static void Succeed <TData>(
     Func <TData, SortDirection, SortIndexResults>[] operators,
     TData data,
     SortDirection sortDirection,
     SortIndexResults expected)
     where TData : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](data, sortDirection);
         DoubleMatrixAssert.AreEqual(
             expected: expected.SortedData,
             actual: actual.SortedData,
             delta: DoubleMatrixTest.Accuracy);
         IndexCollectionAssert.AreEqual(
             expected: expected.SortedIndexes,
             actual: actual.SortedIndexes);
     }
 }
        /// <summary>
        /// Checks that the specified <see cref="IndexPartition{T}"/>
        /// instances are equal.
        /// </summary>
        /// <param name="expected">The expected partition.</param>
        /// <param name="actual">The actual partition.</param>
        public static void AreEqual <T>(
            IndexPartition <T> expected,
            IndexPartition <T> actual)
        {
            if (null == expected && null == actual)
            {
                return;
            }

            if (((null == expected) && (null != actual))
                ||
                ((null != expected) && (null == actual)))
            {
                throw new AssertFailedException(
                          "One IndexPartition instance is null, the other is not.");
            }

            int expectedCount = expected.Count;
            int actualCount   = actual.Count;

            if (expectedCount != actualCount)
            {
                throw new AssertFailedException(
                          "IndexPartition instances have not the same number of parts.");
            }

            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(
                    expected.Identifiers[i],
                    actual.Identifiers[i],
                    "Wrong part identifier at position: {0}", i);

                var expectedPart = expected[expected.Identifiers[i]];
                var actualPart   = actual[actual.Identifiers[i]];
                IndexCollectionAssert.AreEqual(expectedPart, actualPart);
            }
        }