示例#1
0
        public void MatrixAddRowsOutOfRange(int startRow)
        {
            Matrix m = Setup.GetTestMatrix1();

            Assert.Throws <IndexOutOfRangeException>(() => m.AddRows(startRow, 1, 0));
            Assert.Throws <IndexOutOfRangeException>(() => Matrix.AddRows(Setup.GetTestMatrix1(), startRow, 1, 0));
        }
        public void MatrixIndexSingleIndexOutOfRangeException()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            int    size        = testMatrix1.Size;

            Assert.Throws <IndexOutOfRangeException>(() => testMatrix1[size]);
        }
示例#3
0
        public void MatrixExtractIndexOutOfRange(int start)
        {
            Matrix m1 = Setup.GetTestMatrix1();

            Assert.Throws <IndexOutOfRangeException>(() => m1.Extract(start, 1, 1));
            Assert.Throws <IndexOutOfRangeException>(() => Matrix.Extract(Setup.GetTestMatrix1(), start, 1, 1));
        }
示例#4
0
        public void MatrixRemoveColumnsOutOfRange(int startColumn)
        {
            Matrix m = Setup.GetTestMatrix1();

            Assert.Throws <IndexOutOfRangeException>(() => m.RemoveColumns(startColumn, 1));
            Assert.Throws <IndexOutOfRangeException>(() => Matrix.RemoveColumns(Setup.GetTestMatrix1(), startColumn, 1));
        }
示例#5
0
        public void MatrixOperationsJoinRowsIncorrectDimensions()
        {
            Matrix m1 = Setup.GetTestMatrix1();

            Assert.Throws <InvalidMatrixDimensionsException>(() => m1.Join(Setup.GetTestMatrix3(), MatrixDimension.Rows));
            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.Join(Setup.GetTestMatrix1(), Setup.GetTestMatrix3(), MatrixDimension.Rows));
        }
示例#6
0
        public void MatrixExtractColumnsZeroColumns()
        {
            Matrix m = Setup.GetTestMatrix1();

            Assert.Throws <InvalidMatrixDimensionsException>(() => m.ExtractColumns(0, 0));
            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.ExtractColumns(Setup.GetTestMatrix1(), 0, 0));
        }
示例#7
0
        public void MatrixExtractColumnsOutOfRange(int startColumn, int count)
        {
            Matrix m = Setup.GetTestMatrix1();

            Assert.Throws <IndexOutOfRangeException>(() => m.ExtractColumns(startColumn, count));
            Assert.Throws <IndexOutOfRangeException>(() => Matrix.ExtractColumns(Setup.GetTestMatrix1(), startColumn, count));
        }
示例#8
0
        public void MatrixExtractInvalidDimensions(int start, int rows, int columns)
        {
            Matrix m1 = Setup.GetTestMatrix1();

            Assert.Throws <InvalidMatrixDimensionsException>(() => m1.Extract(start, rows, columns));
            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.Extract(Setup.GetTestMatrix1(), start, rows, columns));
        }
        public void MatrixMultiplyTransposeByMatrixMatrixInvalidDimensions()
        {
            Matrix m1 = Setup.GetTestMatrix3();
            Matrix m2 = Setup.GetTestMatrix1();

            Assert.Throws <InvalidMatrixDimensionsException>(() => m1.MultiplyTransposeBy(m2));
            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.MultiplyTransposeBy(m1, m2));
        }
        public void MatrixIndexRowColumnIndexOutOfRangeException()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            int    row         = testMatrix1.Rows;
            int    columns     = testMatrix1.Columns;

            Assert.Throws <IndexOutOfRangeException>(() => testMatrix1[row, columns]);
        }
示例#11
0
        public void MatrixInverseNonSquareMatrix()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Matrix m = new Matrix(testMatrix1);

            Assert.Throws <InvalidMatrixDimensionsException>(() => m.Inverse());
            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.Inverse(m));
        }
示例#12
0
        public void MatrixEnumerator()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            double start       = 1.0;

            foreach (double d in testMatrix1)
            {
                Assert.Equal(start++, d);
            }
        }
        public void MatrixAddMatrixScalarFluent(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            double scalar   = 3.0;
            Matrix m        = new Matrix(testMatrix1).Add(scalar).Add(scalar);
            Matrix expected = testMatrix1 + (scalar * 2);

            Assert.Equal(expected, m);
        }
        public void MatrixIndexSingle()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Assert.Equal(1.0, testMatrix1[0]);
            Assert.Equal(2.0, testMatrix1[1]);
            Assert.Equal(3.0, testMatrix1[2]);
            Assert.Equal(4.0, testMatrix1[3]);
            Assert.Equal(5.0, testMatrix1[4]);
            Assert.Equal(6.0, testMatrix1[5]);
        }
        public void MatrixSubtractMatrixNull(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Assert.Throws <NullReferenceException>(() => Matrix.Subtract(testMatrix1, null));
            Matrix m1 = new Matrix(testMatrix1);

            Assert.Throws <NullReferenceException>(() => m1.Subtract(null));
            Assert.Throws <NullReferenceException>(() => m1 - null);
        }
示例#16
0
        public void MatrixElementOperationInvalidDimensions(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            Matrix testMatrix3 = Setup.GetTestMatrix3();

            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.ElementOperation(testMatrix1, testMatrix3, (a, b) => a + b));
            Matrix m1 = new Matrix(testMatrix1);

            Assert.Throws <InvalidMatrixDimensionsException>(() => m1.ElementOperation(testMatrix3, (a, b) => a + b));
        }
        public void MatrixMultiplyMatrixNull(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Assert.Throws <NullReferenceException>(() => Matrix.Multiply(testMatrix1, null));
            Matrix m1 = null;

            Assert.Throws <NullReferenceException>(() => testMatrix1 * m1);
            Assert.Throws <NullReferenceException>(() => testMatrix1.Multiply(m1));
        }
        public void MatrixAddNullMatrix(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Assert.Throws <NullReferenceException>(() => Matrix.Add(null, testMatrix1));
            Matrix m1 = null;

            Assert.Throws <NullReferenceException>(() => m1.Add(testMatrix1));
            Assert.Throws <NullReferenceException>(() => m1 + testMatrix1);
        }
        public void MatrixIndexRowColumn()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            Assert.Equal(1.0, testMatrix1[0, 0]);
            Assert.Equal(2.0, testMatrix1[0, 1]);
            Assert.Equal(3.0, testMatrix1[0, 2]);
            Assert.Equal(4.0, testMatrix1[1, 0]);
            Assert.Equal(5.0, testMatrix1[1, 1]);
            Assert.Equal(6.0, testMatrix1[1, 2]);
        }
        public void MatrixMultiplyMatrixMatrixInvalidDimensions(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            Matrix testMatrix2 = Setup.GetTestMatrix2();

            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.Multiply(testMatrix1, testMatrix2));
            Matrix m1 = new Matrix(testMatrix1);

            Assert.Throws <InvalidMatrixDimensionsException>(() => testMatrix1 * testMatrix2);
            Assert.Throws <InvalidMatrixDimensionsException>(() => testMatrix1.Multiply(testMatrix2));
        }
示例#21
0
        public void MatrixRemoveColumnsZeroColumns()
        {
            Matrix m1 = Setup.GetTestMatrix1();
            Matrix m2 = Matrix.RemoveColumns(Setup.GetTestMatrix1(), 1, 0);

            m1.RemoveColumns(1, 0);

            Matrix expected = Setup.GetTestMatrix1();

            Assert.True(expected == m1);
            Assert.True(expected == m2);
        }
        public void MatrixSubtractMatrixMatrixInvalidDimensions(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            Matrix testMatrix3 = Setup.GetTestMatrix3();

            Assert.Throws <InvalidMatrixDimensionsException>(() => Matrix.Subtract(testMatrix1, testMatrix3));
            Matrix m1 = new Matrix(testMatrix1);

            Assert.Throws <InvalidMatrixDimensionsException>(() => m1.Subtract(testMatrix3));
            Assert.Throws <InvalidMatrixDimensionsException>(() => testMatrix1 - testMatrix3);
        }
        public void MatrixMultiplyByOwnTransposeMatrix()
        {
            Matrix m1       = Setup.GetTestMatrix1();
            Matrix m2       = Setup.GetTestMatrix1Transposed();
            Matrix expected = m1 * m2;

            Matrix test1 = Setup.GetTestMatrix1().MultiplyByOwnTranspose();
            Matrix test2 = Matrix.MultiplyByOwnTranspose(Setup.GetTestMatrix1());

            Assert.True(expected == test1);
            Assert.True(expected == test2);
        }
示例#24
0
        public void MatrixAddRowsZeroRows()
        {
            Matrix m1 = Setup.GetTestMatrix1();
            Matrix m2 = Matrix.AddRows(Setup.GetTestMatrix1(), 1, 0, 2.0);

            m1.AddRows(1, 0, 2.0);

            Matrix expected = Setup.GetTestMatrix1();

            Assert.True(expected == m1);
            Assert.True(expected == m2);
        }
        public void MatrixIndexSingleTransposeSwapDimensions()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            Matrix m           = new Matrix(testMatrix1);

            m.Transpose(true);
            Assert.Equal(1.0, m[0]);
            Assert.Equal(4.0, m[1]);
            Assert.Equal(2.0, m[2]);
            Assert.Equal(5.0, m[3]);
            Assert.Equal(3.0, m[4]);
            Assert.Equal(6.0, m[5]);
        }
        public void MatrixIndexRowColumnTransposeSwapDimensions()
        {
            Matrix testMatrix1 = Setup.GetTestMatrix1();
            Matrix m           = new Matrix(testMatrix1);

            m.Transpose(true);
            Assert.Equal(1.0, m[0, 0]);
            Assert.Equal(2.0, m[1, 0]);
            Assert.Equal(3.0, m[2, 0]);
            Assert.Equal(4.0, m[0, 1]);
            Assert.Equal(5.0, m[1, 1]);
            Assert.Equal(6.0, m[2, 1]);
        }
        public void MatrixMultiplyTransposeByMatrixSwapDimensions()
        {
            Matrix m1       = Setup.GetTestMatrix1();
            Matrix m2       = Matrix.Transpose(Setup.GetTestMatrix1());
            Matrix expected = m1 * m2;

            Matrix test1 = Matrix.MultiplyOwnTransposeBy(Setup.GetTestMatrix1().Transpose(true));
            Matrix test2 = Setup.GetTestMatrix1().Transpose(true);

            test2.MultiplyOwnTransposeBy();

            Assert.True(expected == test1);
            Assert.True(expected == test2);
        }
        public void MatrixMultiplyMatrixScalarFluent(IMatrixArithmetic arithmetic)
        {
            Matrix.Arithmetic = arithmetic;
            Matrix testMatrix1 = Setup.GetTestMatrix1();

            double scalar = 3.0;
            Matrix m      = new Matrix(testMatrix1);

            m.Multiply(scalar).Multiply(scalar);

            Matrix expected = testMatrix1 * (scalar * scalar);

            Assert.Equal(expected, m);
        }
        public void MatrixMultiplyTransposeByMatrixSwapDimensionsMatrix()
        {
            Matrix m1       = Setup.GetTestMatrix3();
            Matrix m2       = Setup.GetTestMatrix1();
            Matrix expected = m1 * m2;

            Matrix test1 = Matrix.MultiplyTransposeBy(m1.Transpose(true), Setup.GetTestMatrix1());
            Matrix test2 = Setup.GetTestMatrix3().Transpose(true);

            test2.MultiplyTransposeBy(Setup.GetTestMatrix1());

            Assert.True(test1 == expected);
            Assert.True(test2 == expected);
        }
        public void MatrixMultiplyTransposeByMatrixMatrix()
        {
            Matrix m1       = Matrix.Transpose(Setup.GetTestMatrix1());
            Matrix m2       = Setup.GetTestMatrix2();
            Matrix expected = m1 * m2;

            Matrix test1 = Matrix.MultiplyTransposeBy(Setup.GetTestMatrix1(), m2);
            Matrix test2 = Setup.GetTestMatrix1();

            test2.MultiplyTransposeBy(Setup.GetTestMatrix2());

            Assert.True(test1 == expected);
            Assert.True(test2 == expected);
        }