static void Succeed <TOperand>(
     Func <TOperand, DoubleMatrix>[] operators,
     TOperand operand,
     DoubleMatrixState expected)
     where TOperand : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](operand);
         DoubleMatrixAssert.IsStateAsExpected(
             expectedState: expected,
             actualMatrix: actual,
             delta: DoubleMatrixTest.Accuracy);
     }
 }
Beispiel #2
0
 static void Succeed <TData>(
     Func <TData, DataOperation, DoubleMatrix>[] operators,
     TData data,
     DataOperation dataOperation,
     DoubleMatrixState expected)
     where TData : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](data, dataOperation);
         DoubleMatrixAssert.IsStateAsExpected(
             expectedState: expected,
             actualMatrix: actual,
             delta: DoubleMatrixTest.Accuracy);
     }
 }
        /// <summary>
        /// Determines whether the specified matrix has the expected state.
        /// </summary>
        /// <param name="expectedState">The expected state.</param>
        /// <param name="actualMatrix">The actual matrix.</param>
        /// <param name="delta">The required precision.</param>
        public static void IsStateAsExpected(
            DoubleMatrixState expectedState,
            DoubleMatrix actualMatrix,
            double delta)
        {
            // Null reference ?

            Assert.IsNotNull(actualMatrix);

            // Matrix Fields

            object implementor = Reflector.GetField(
                actualMatrix,
                "implementor");

            Assert.IsNotNull(implementor);

            double[] actualColumnMajorOrderedEntries;

            actualColumnMajorOrderedEntries =
                (double[])Reflector.ExecuteMember(
                    implementor,
                    "AsColumnMajorDenseArray",
                    null);

            Assert.IsNotNull(actualColumnMajorOrderedEntries);

            var expectedColumnMajorOrderedEntries = expectedState.AsColumnMajorDenseArray;

            Assert.AreEqual(
                expectedColumnMajorOrderedEntries.Length,
                actualColumnMajorOrderedEntries.Length);

            for (int Id = 0; Id < actualColumnMajorOrderedEntries.Length; Id++)
            {
                if (Double.IsNaN(expectedColumnMajorOrderedEntries[Id]))
                {
                    Assert.IsTrue(Double.IsNaN(actualColumnMajorOrderedEntries[Id]));
                }
                else
                {
                    Assert.AreEqual(
                        expectedColumnMajorOrderedEntries[Id],
                        actualColumnMajorOrderedEntries[Id], delta);
                }
            }

            int actualNumberOfRows = (int)Reflector.GetProperty(
                implementor,
                "NumberOfRows");

            int expectedNumberOfRows = expectedState.NumberOfRows;

            Assert.AreEqual(expectedNumberOfRows, actualNumberOfRows);

            int actualNumberOfColumns = (int)Reflector.GetProperty(
                implementor,
                "NumberOfColumns");

            int expectedNumberOfColumns = expectedState.NumberOfColumns;

            Assert.AreEqual(expectedNumberOfColumns, actualNumberOfColumns);

            // Matrix Names

            // Matrix name

            Assert.AreEqual(expectedState.Name, actualMatrix.Name);

            // Row names

            // Both have row names
            bool expectedHasRowNames = expectedState.RowNames is not null;

            Assert.AreEqual(expectedHasRowNames, actualMatrix.HasRowNames);

            if (expectedHasRowNames)
            {
                CompareDimensionNames("row", expectedState.RowNames, actualMatrix.RowNames);
            }

            // Column names

            // Both have column names
            bool expectedHasColumnNames = expectedState.ColumnNames is not null;

            Assert.AreEqual(expectedHasColumnNames, actualMatrix.HasColumnNames);

            if (expectedHasColumnNames)
            {
                CompareDimensionNames("column", expectedState.ColumnNames, actualMatrix.ColumnNames);
            }
        }