예제 #1
0
        public void ZDataTest()
        {
            var matrix = ComplexMatrix.Dense(2, 3,
                                             new Complex[6] {
                1, 2, 3, 4, 5, 6
            });
            var rows = matrix.AsRowCollection();

            int dataColumn = 1;

            rows.ZDataColumn = dataColumn;

            ComplexMatrixRow row = rows[0];

            // Same value: unspecific notification
            var subscriber = new PropertyChangedSubscriber();

            row.PropertyChanged += subscriber.PropertyChangedEventHandler;

            Complex expected = matrix[row.Index, dataColumn];

            row.ZData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "" },
                actual : subscriber.PropertyNames.ToArray());

            var actual = row.ZData;

            ComplexAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);

            // Different value: specific notification
            subscriber           = new PropertyChangedSubscriber();
            row.PropertyChanged += subscriber.PropertyChangedEventHandler;

            row.ZData = -1;
            ComplexAssert.AreEqual(
                matrix[row.Index, dataColumn],
                row.ZData,
                ComplexMatrixTest.Accuracy);
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "", "ZData", "[1]" },
                actual : subscriber.PropertyNames.ToArray());
        }
예제 #2
0
        public void ConstructorTest()
        {
            var matrix = ComplexMatrix.Dense(2, 3,
                                             new Complex[6] {
                1, 2, 3, 4, 5, 6
            });
            var rows = matrix.AsRowCollection();

            for (int i = 0; i < matrix.NumberOfRows; i++)
            {
                var row = rows[i];
                Assert.AreEqual(i, row.Index);
                Assert.AreEqual(matrix.NumberOfColumns, row.Length);
                matrix.TryGetRowName(i, out string expectedRowName);

                Assert.AreEqual(expectedRowName, row.Name);

                for (int j = 0; j < matrix.NumberOfColumns; j++)
                {
                    ComplexAssert.AreEqual(matrix[i, j], row[j], ComplexMatrixTest.Accuracy);
                }
            }
        }
예제 #3
0
        public void IndexerInt32SetTest()
        {
            // columnIndex is less than 0
            {
                ComplexMatrix matrix = ComplexMatrix.Dense(2, 3,
                                                           new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                var target = rows[0];

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    target[-1] = -1;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS"),
                    expectedParameterName: "columnIndex");
            }

            // columnIndex is greater than NumberOfColumns - 1
            {
                ComplexMatrix matrix = ComplexMatrix.Dense(2, 3,
                                                           new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                var target = rows[0];

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    target[matrix.NumberOfColumns] = -1;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS"),
                    expectedParameterName: "columnIndex");
            }

            // columnIndex is inside the bounds
            {
                var subscriber = new PropertyChangedSubscriber();

                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });
                var rows = matrix.AsRowCollection();

                int dataColumn = 2;
                rows.XDataColumn = dataColumn;
                rows.YDataColumn = dataColumn;
                rows.ZDataColumn = dataColumn;

                int rowIndex         = 1;
                ComplexMatrixRow row = rows[rowIndex];
                row.PropertyChanged += subscriber.PropertyChangedEventHandler;

                row[dataColumn] = -1;
                ComplexAssert.AreEqual(
                    matrix[rowIndex, dataColumn],
                    row[dataColumn],
                    ComplexMatrixTest.Accuracy);
                ArrayAssert <string> .AreEqual(
                    expected : new string[] { "", "[2]", "XData", "YData", "ZData" },
                    actual : subscriber.PropertyNames.ToArray());

                row[0] = -1;
                ComplexAssert.AreEqual(
                    matrix[rowIndex, dataColumn],
                    row[dataColumn],
                    ComplexMatrixTest.Accuracy);
                ArrayAssert <string> .AreEqual(
                    expected : new string[] { "", "[2]", "XData", "YData", "ZData", "[0]" },
                    actual : subscriber.PropertyNames.ToArray());
            }
        }
예제 #4
0
        public void DataTest()
        {
            PropertyChangedSubscriber subscriber;
            Complex          expected;
            ComplexMatrixRow row;

            var matrix = ComplexMatrix.Dense(3, 3,
                                             new Complex[9] {
                1, 4, 1, 2, 5, 2, 3, 6, 3
            },
                                             StorageOrder.ColumnMajor);

            var rows = matrix.AsRowCollection();

            // m = [  1  2  3
            //        4  5  6
            //        1  2  3  ]

            rows.XDataColumn = 2;
            rows.YDataColumn = 1;
            rows.ZDataColumn = 0;

            int rowIndex = 1;

            row                  = rows[rowIndex];
            subscriber           = new PropertyChangedSubscriber();
            row.PropertyChanged += subscriber.PropertyChangedEventHandler;

            // Setting without changing values

            expected  = matrix[rowIndex, rows.XDataColumn];
            row.XData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "" },
                actual : subscriber.PropertyNames.ToArray());

            expected  = matrix[rowIndex, rows.YDataColumn];
            row.YData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "" },
                actual : subscriber.PropertyNames.ToArray());

            expected  = matrix[rowIndex, rows.ZDataColumn];
            row.ZData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "" },
                actual : subscriber.PropertyNames.ToArray());

            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.XDataColumn],
                row.XData,
                ComplexMatrixTest.Accuracy);
            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.YDataColumn],
                row.YData,
                ComplexMatrixTest.Accuracy);
            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.ZDataColumn],
                row.ZData,
                ComplexMatrixTest.Accuracy);

            // Setting by changing values

            expected  = -5.0;
            row.XData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "", "XData", "[2]" },
                actual : subscriber.PropertyNames.ToArray());

            expected  = -10.0;
            row.YData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "", "XData", "[2]", "YData", "[1]" },
                actual : subscriber.PropertyNames.ToArray());

            expected  = -15.0;
            row.ZData = expected;
            ArrayAssert <string> .AreEqual(
                expected : new string[] { "", "XData", "[2]", "YData", "[1]", "ZData", "[0]" },
                actual : subscriber.PropertyNames.ToArray());

            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.XDataColumn],
                row.XData,
                ComplexMatrixTest.Accuracy);
            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.YDataColumn],
                row.YData,
                ComplexMatrixTest.Accuracy);
            ComplexAssert.AreEqual(
                matrix[rowIndex, rows.ZDataColumn],
                row.ZData,
                ComplexMatrixTest.Accuracy);
        }
예제 #5
0
        public void GetEnumeratorTest()
        {
            // IEnumerable.GetEnumerator
            {
                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                for (int i = 0; i < matrix.NumberOfRows; i++)
                {
                    var         target     = rows[i];
                    IEnumerable enumerable = (IEnumerable)target;

                    IEnumerator enumerator = enumerable.GetEnumerator();
                    object      current;
                    int         index = 0;

                    while (enumerator.MoveNext())
                    {
                        current = enumerator.Current;
                        ComplexAssert.AreEqual(target[index], (Complex)current, ComplexMatrixTest.Accuracy);
                        index++;
                    }

                    // reset
                    enumerator.Reset();

                    Assert.AreEqual(-1, (int)Reflector.GetField(enumerator, "position"));

                    // dispose
                    enumerator = null;
                    GC.Collect(10, GCCollectionMode.Forced);
                }
            }

            // IEnumerable<Complex>.GetEnumerator
            {
                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                for (int i = 0; i < matrix.NumberOfRows; i++)
                {
                    var target = rows[i];
                    IEnumerable <Complex> enumerable = (IEnumerable <Complex>)target;

                    IEnumerator <Complex> enumerator = enumerable.GetEnumerator();

                    int     index = 0;
                    Complex current;

                    while (enumerator.MoveNext())
                    {
                        current = enumerator.Current;
                        ComplexAssert.AreEqual(target[index], current, ComplexMatrixTest.Accuracy);
                        index++;
                    }

                    // reset
                    enumerator.Reset();

                    Assert.AreEqual(-1, (int)Reflector.GetField(enumerator, "position"));

                    // dispose
                    enumerator.Dispose();
                }
            }

            // IEnumerable<Complex>.Current fails
            {
                string STR_EXCEPT_ENU_OUT_OF_BOUNDS =
                    (string)Reflector.ExecuteStaticMember(
                        typeof(ImplementationServices),
                        "GetResourceString",
                        new string[] { "STR_EXCEPT_ENU_OUT_OF_BOUNDS" });

                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                for (int i = 0; i < matrix.NumberOfRows; i++)
                {
                    var target     = rows[i];
                    var enumerable = (IEnumerable <Complex>)target;

                    var enumerator = enumerable.GetEnumerator();

                    ExceptionAssert.Throw(
                        () =>
                    {
                        Complex current = enumerator.Current;
                    },
                        expectedType: typeof(InvalidOperationException),
                        expectedMessage: STR_EXCEPT_ENU_OUT_OF_BOUNDS);
                }
            }

            // IEnumerable.Current fails
            {
                string STR_EXCEPT_ENU_OUT_OF_BOUNDS =
                    (string)Reflector.ExecuteStaticMember(
                        typeof(ImplementationServices),
                        "GetResourceString",
                        new string[] { "STR_EXCEPT_ENU_OUT_OF_BOUNDS" });

                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                for (int i = 0; i < matrix.NumberOfRows; i++)
                {
                    var target     = rows[i];
                    var enumerable = (IEnumerable)target;

                    var enumerator = enumerable.GetEnumerator();

                    ExceptionAssert.Throw(
                        () =>
                    {
                        object current = enumerator.Current;
                    },
                        expectedType: typeof(InvalidOperationException),
                        expectedMessage: STR_EXCEPT_ENU_OUT_OF_BOUNDS);
                }
            }
        }
        public void XDataColumnTest()
        {
            // value is less than 0
            {
                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });
                var rows = matrix.AsRowCollection();

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    rows.XDataColumn = -1;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_ROW_DATA_COLUMN_EXCEEDS_DIMS"),
                    expectedParameterName: "value");
            }

            // value is greater than NumberOfColumns - 1
            {
                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });
                var rows = matrix.AsRowCollection();

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    rows.XDataColumn = matrix.NumberOfColumns;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_ROW_DATA_COLUMN_EXCEEDS_DIMS"),
                    expectedParameterName: "value");
            }

            // value is inside the bounds
            {
                var matrix = ComplexMatrix.Dense(2, 3,
                                                 new Complex[6] {
                    1, 2, 3, 4, 5, 6
                });
                var rows = matrix.AsRowCollection();

                int dataColumn = 1;

                rows.XDataColumn = dataColumn;

                ComplexMatrixRow row = rows[0];
                var subscriber       = new PropertyChangedSubscriber();
                row.PropertyChanged += subscriber.PropertyChangedEventHandler;

                // Same value: unspecific notification
                Complex expected = matrix[row.Index, dataColumn];
                row[dataColumn] = expected;
                ArrayAssert <string> .AreEqual(
                    expected : new string[] { "" },
                    actual : subscriber.PropertyNames.ToArray());

                var actual = row[dataColumn];
                ComplexAssert.AreEqual(
                    expected,
                    actual,
                    ComplexMatrixTest.Accuracy);

                // Different value: specific notification
                row[dataColumn] = -1;
                ComplexAssert.AreEqual(
                    matrix[row.Index, dataColumn],
                    row[dataColumn],
                    ComplexMatrixTest.Accuracy);
                ArrayAssert <string> .AreEqual(
                    expected : new string[] { "", "[1]", "XData" },
                    actual : subscriber.PropertyNames.ToArray());
            }
        }