Exemple #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());
        }
Exemple #2
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());
            }
        }
Exemple #3
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);
        }
Exemple #4
0
        public void IndexSetTest()
        {
            // value 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.Index = -1;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS"),
                    expectedParameterName: "value");
            }

            // value 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.Index = matrix.NumberOfColumns;
                },
                    expectedType: typeof(ArgumentOutOfRangeException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS"),
                    expectedParameterName: "value");
            }

            // Setting Index without changing its value
            {
                var subscriber = new PropertyChangedSubscriber();

                ComplexMatrix 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];

                    target.PropertyChanged += subscriber.PropertyChangedEventHandler;

                    target.Index = i;

                    Assert.AreEqual(expected: i, actual: target.Index);
                }
            }

            // Setting Index changing its value
            {
                var subscriber = new PropertyChangedSubscriber();

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

                var rows = matrix.AsRowCollection();

                var target = rows[0];

                target.PropertyChanged += subscriber.PropertyChangedEventHandler;

                int expectedIndex = 1;
                target.Index = expectedIndex;

                Assert.AreEqual(expectedIndex, target.Index);

                ComplexMatrixAssert.AreEqual(
                    matrix[expectedIndex, ":"], target, ComplexMatrixTest.Accuracy);
            }
        }
Exemple #5
0
        public void IndexerStringGetTest()
        {
            // columnIndex not representing an integer
            {
                DoubleMatrix matrix = DoubleMatrix.Dense(2, 3,
                                                         new double[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                var target = rows[0];

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    var actual = target["A"];
                },
                    expectedType: typeof(ArgumentException),
                    expectedPartialMessage: ImplementationServices.GetResourceString(
                        "STR_EXCEPT_PAR_CANNOT_PARSE_AS_INT32"),
                    expectedParameterName: "columnIndex");
            }

            // columnIndex is less than 0
            {
                DoubleMatrix matrix = DoubleMatrix.Dense(2, 3,
                                                         new double[6] {
                    1, 2, 3, 4, 5, 6
                });

                var rows = matrix.AsRowCollection();

                var target = rows[0];

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

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

                var rows = matrix.AsRowCollection();

                var target = rows[0];

                ArgumentExceptionAssert.Throw(
                    () =>
                {
                    var actual = target["3"];
                },
                    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 = DoubleMatrix.Dense(2, 3,
                                                new double[6] {
                    1, 2, 3, 4, 5, 6
                });
                var rows = matrix.AsRowCollection();

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

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

                row[dataColumn] = -1;
                Assert.AreEqual(matrix[rowIndex, dataColumn], row["2"]);
                ArrayAssert <string> .AreEqual(
                    expected : new string[] { "", "[2]", "XData", "YData" },
                    actual : subscriber.PropertyNames.ToArray());
            }
        }
        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());
            }
        }