Example #1
0
        /// <summary>
        /// Asserts that the specified objects are equal.
        /// </summary>
        /// <param name="expected">The expected array.</param>
        /// <param name="actual">The actual array.</param>
        /// <param name="delta">The required accuracy.</param>
        /// <exception cref="AssertFailedException">
        /// One array is null, the other is not.</br>
        /// -or-</br>
        /// The arrays have not the same length.</br>
        /// -or-</br>
        /// A value is unexpected at a given position.
        /// </exception>
        public static void AreEqual(
            Complex[] expected, Complex[] actual, double delta)
        {
            if (null == expected && null == actual)
            {
                return;
            }

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

            int expectedLength = expected.Length;
            int actualLength   = actual.Length;

            if (expectedLength != actualLength)
            {
                throw new AssertFailedException("The arrays have not the same length.");
            }

            for (int l = 0; l < expectedLength; l++)
            {
                ComplexAssert.AreEqual(expected[l], actual[l], delta);
            }
        }
Example #2
0
        /// <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(
            ComplexMatrixState expectedState,
            ComplexMatrix actualMatrix,
            double delta)
        {
            // Null reference ?

            Assert.IsNotNull(actualMatrix);

            // Matrix Fields

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

            Assert.IsNotNull(implementor);

            Complex[] actualColumnMajorOrderedEntries;

            actualColumnMajorOrderedEntries =
                (Complex[])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++)
            {
                ComplexAssert.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);
            }
        }
Example #3
0
        /// <summary>
        /// Checks that the specified <see cref="ComplexMatrix"/>
        /// instances are equal.
        /// </summary>
        /// <param name="expected">The expected matrix.</param>
        /// <param name="actual">The actual matrix.</param>
        /// <param name="delta">The required accuracy.</param>
        public static void AreEqual(
            ComplexMatrix expected,
            ComplexMatrix actual,
            double delta)
        {
            // Null references ?

            Assert.IsNotNull(expected);
            Assert.IsNotNull(actual);

            // Matrix Fields

            object expectedImplementor = Reflector.GetField(
                expected,
                "implementor");

            Assert.IsNotNull(expectedImplementor);

            var expectedColumnMajorOrderedEntries =
                (Complex[])Reflector.ExecuteMember(
                    expectedImplementor,
                    "AsColumnMajorDenseArray",
                    null);

            Assert.IsNotNull(expectedColumnMajorOrderedEntries);

            object actualImplementor = Reflector.GetField(
                actual,
                "implementor");

            Assert.IsNotNull(actualImplementor);

            var actualColumnMajorOrderedEntries =
                (Complex[])Reflector.ExecuteMember(
                    actualImplementor,
                    "AsColumnMajorDenseArray",
                    null);

            Assert.IsNotNull(actualColumnMajorOrderedEntries);

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

            for (int l = 0; l < actualColumnMajorOrderedEntries.Length; l++)
            {
                ComplexAssert.AreEqual(
                    expectedColumnMajorOrderedEntries[l],
                    actualColumnMajorOrderedEntries[l],
                    ComplexMatrixTest.Accuracy);
            }

            int expectedNumberOfRows = (int)Reflector.GetProperty(
                expectedImplementor,
                "NumberOfRows");

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

            Assert.AreEqual(expectedNumberOfRows, actualNumberOfRows);

            int expectedNumberOfColumns = (int)Reflector.GetProperty(
                expectedImplementor,
                "NumberOfColumns");

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

            Assert.AreEqual(expectedNumberOfColumns, actualNumberOfColumns);

            // Matrix Names

            MatrixNamesAreEqual(expected, actual);
        }