コード例 #1
0
        public void ToComplexMatrixTest()
        {
            // value is null
            {
                ComplexMatrix actual = (ComplexMatrixRow)(null);

                Assert.IsNull(actual);

                actual = ComplexMatrixRow.ToComplexMatrix(null);

                Assert.IsNull(actual);
            }

            // value is not null
            {
                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           expected = matrix[i, ":"];
                    ComplexMatrix actual   = rows[i];
                    ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);

                    actual = ComplexMatrixRow.ToComplexMatrix(rows[i]);
                    ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
                }
            }
        }
コード例 #2
0
        public void LengthTest()
        {
            ComplexMatrix matrix = ComplexMatrix.Dense(2, 3,
                                                       new Complex[6] {
                1, 2, 3, 4, 5, 6
            });
            var rows = matrix.AsRowCollection();

            ComplexMatrixRow target = rows[0];
            var actual = target.Length;

            var expected = matrix.NumberOfColumns;

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void NotifyPropertyChangedTest()
        {
            ComplexMatrix matrix = ComplexMatrix.Dense(2, 3,
                                                       new Complex[6] {
                1, 2, 3, 4, 5, 6
            });

            var rows = matrix.AsRowCollection();

            ComplexMatrixRow target = rows[0];

            target.PropertyChanged += new PropertyChangedEventHandler(
                this.PropertyChangedEventHandler);

            string propertyName = "UNKNOWN";

            target.NotifyPropertyChanged(propertyName);
        }
コード例 #4
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());
        }
コード例 #5
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());
            }
        }
コード例 #6
0
        public void EqualityTest()
        {
            ComplexMatrix    matrix, otherMatrix;
            ComplexMatrixRow thisRow, otherRow;

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

            var rows = matrix.AsRowCollection();

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

            // STRONGLY TYPED COMPARISON

            // Length difference > 0

            otherMatrix = ComplexMatrix.Dense(3, 4);
            var otherRows = otherMatrix.AsRowCollection();

            thisRow  = rows[0];
            otherRow = otherRows[0];

            Assert.IsTrue(thisRow != otherRow);
            Assert.IsFalse(thisRow == otherRow);
            Assert.IsFalse(thisRow.Equals(otherRow));

            // Length difference < 0

            otherMatrix = ComplexMatrix.Dense(3, 2);
            otherRows   = otherMatrix.AsRowCollection();

            thisRow  = rows[0];
            otherRow = otherRows[0];

            Assert.IsTrue(thisRow != otherRow);
            Assert.IsFalse(thisRow == otherRow);
            Assert.IsFalse(thisRow.Equals(otherRow));

            // Length difference equals 0

            // ----- Rows are equal

            thisRow  = rows[0];
            otherRow = rows[2];

            Assert.IsFalse(thisRow != otherRow);
            Assert.IsTrue(thisRow == otherRow);
            Assert.IsTrue(thisRow.Equals(otherRow));

            // ----- thisRow less than otherRow

            thisRow  = rows[0];
            otherRow = rows[1];

            Assert.IsTrue(thisRow != otherRow);
            Assert.IsFalse(thisRow == otherRow);
            Assert.IsFalse(thisRow.Equals(otherRow));

            // ----- thisRow greater than otherRow

            thisRow  = rows[1];
            otherRow = rows[2];

            Assert.IsTrue(thisRow != otherRow);
            Assert.IsFalse(thisRow == otherRow);
            Assert.IsFalse(thisRow.Equals(otherRow));

            // WEAKLY TYPED COMPARISON

            object weakOther;

            // null other

            thisRow   = rows[1];
            weakOther = null;

            Assert.IsFalse(thisRow.Equals(weakOther));

            // ComplexMatrixRow other

            thisRow   = rows[0];
            weakOther = rows[2];

            Assert.IsTrue(thisRow.Equals(weakOther));

            // other not of type ComplexMatrixRow

            thisRow   = rows[1];
            weakOther = IndexCollection.Default(2);

            Assert.IsFalse(thisRow.Equals(weakOther));

            // COMPARISONS INVOLVING NULL OBJECTS

            ComplexMatrixRow leftRow  = null;
            ComplexMatrixRow rightRow = rows[0];

            Assert.IsFalse(leftRow == rightRow);
            leftRow  = rows[0];
            rightRow = null;
            Assert.IsFalse(leftRow == rightRow);

            leftRow  = null;
            rightRow = null;
            Assert.IsTrue(leftRow == rightRow);
        }
コード例 #7
0
        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());
            }
        }