public void InterfaceGetSubMatrix() { var matrix = MatrixTest.GetTestMatrix(); var subMatrix = matrix.GetSubMatrix(0, 0, 3, 3); Assert.AreEqual(subMatrix.Rows, 3); Assert.AreEqual(subMatrix.Columns, 3); for (var i = 0; i < subMatrix.Rows; i++) { for (var j = 0; j < subMatrix.Columns; j++) { Assert.AreEqual(subMatrix[i, j], i + j); } } subMatrix = (Matrix)((IMatrix <double>)matrix).GetSubMatrix(1, 2, 3, 3); for (var i = 0; i < subMatrix.Rows; i++) { for (var j = 0; j < subMatrix.Columns; j++) { Assert.AreEqual(subMatrix[i, j], i + 1 + j + 2); } } }
public void ExceptionInvalidArrayLength1() { var matrix = MatrixTest.GetTestMatrix(); var array = new double[matrix.Rows * matrix.Columns - 1]; Assert.Throws <ArgumentException>(() => matrix.CopyTo(array, 0)); }
public void Simple1() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.AddRow(); Assert.AreEqual(matrix.Columns, columnCount); Assert.AreEqual(matrix.Rows, rowCount + 1); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCount; j++) { Assert.AreEqual(matrix[i, j], i + j); } } for (var i = 0; i < columnCount; i++) { Assert.AreEqual(matrix[rowCount, i], default(double)); } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; var row = matrix.GetRow(0); Assert.AreEqual(matrix.Columns, columnCount); Assert.AreEqual(matrix.Rows, rowCount); Assert.AreEqual(row.Length, matrix.Columns); for (var i = 0; i < row.Length; i++) { Assert.AreEqual(row[i], i); } row = matrix.GetRow(1); Assert.AreEqual(row.Length, matrix.Columns); for (var i = 0; i < row.Length; i++) { Assert.AreEqual(row[i], i + 1); } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.InterchangeRows(0, 1); Assert.AreEqual(matrix.Columns, columnCount); Assert.AreEqual(matrix.Rows, rowCount); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { if (i == 0) { Assert.AreEqual(matrix[i, j], (i + 1) + (j)); } else if (i == 1) { Assert.AreEqual(matrix[i, j], (i - 1) + (j)); } else { Assert.AreEqual(matrix[i, j], i + j); } } } }
public void MinorArbitraryInterface() { IMathematicalMatrix matrix = MatrixTest.GetTestMatrix(); var rows = matrix.Rows; var columns = matrix.Columns; var minor = matrix.Minor(2, 3); Assert.AreEqual(minor.Columns, columns - 1); Assert.AreEqual(minor.Rows, rows - 1); for (var i = 0; i < minor.Rows; i++) { for (var j = 0; j < minor.Columns; j++) { var addAmount = 0; if (i >= 2) { addAmount++; } if (j >= 3) { addAmount++; } Assert.AreEqual(minor[i, j], i + j + addAmount); } } Assert.IsTrue(MatrixTest.IsOriginalTestMatrix(matrix)); }
public void ConcatenateInterface() { IMathematicalMatrix matrix1 = MatrixTest.GetTestMatrix(); IMathematicalMatrix matrix2 = GetTestMinusMatrix(); var concat = matrix1.Concatenate(matrix2); Assert.AreEqual(concat.Rows, matrix1.Rows); Assert.AreEqual(concat.Columns, matrix1.Columns + matrix2.Columns); for (var i = 0; i < matrix1.Rows; i++) { for (var j = 0; j < matrix1.Columns; j++) { Assert.AreEqual(concat[i, j], matrix1[i, j]); } } for (var i = 0; i < matrix2.Rows; i++) { for (var j = 0; j < matrix2.Columns; j++) { Assert.AreEqual(concat[i, j + matrix1.Columns], matrix2[i, j]); } } }
public void Simple2() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.AddRow(0, -1, -2, -3, -4); Assert.AreEqual(matrix.Columns, columnCount); Assert.AreEqual(matrix.Rows, rowCount + 1); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCount; j++) { Assert.AreEqual(matrix[i, j], i + j); } } for (var i = 0; i < columnCount; i++) { Assert.AreEqual(matrix[rowCount, i], -1 * i); } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var subMatrix = matrix.GetSubMatrix(0, 0, 3, 3); Assert.AreEqual(subMatrix.Rows, 3); Assert.AreEqual(subMatrix.Columns, 3); for (var i = 0; i < subMatrix.Rows; i++) { for (var j = 0; j < subMatrix.Columns; j++) { Assert.AreEqual(subMatrix[i, j], i + j); } } subMatrix = matrix.GetSubMatrix(1, 2, 3, 3); for (var i = 0; i < subMatrix.Rows; i++) { for (var j = 0; j < subMatrix.Columns; j++) { Assert.AreEqual(subMatrix[i, j], i + 1 + j + 2); } } }
public void Larger() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.Resize(8, 8); Assert.AreEqual(matrix.Columns, 8); Assert.AreEqual(matrix.Rows, 8); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCount; j++) { Assert.AreEqual(matrix[i, j], i + j); } } for (var i = rowCount; i < 8; i++) { for (var j = columnCount; j < 8; j++) { Assert.AreEqual(matrix[i, j], default(double)); } } }
public void MultipleColumns() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.AddColumns(3); Assert.AreEqual(matrix.Columns, columnCount + 3); Assert.AreEqual(matrix.Rows, rowCount); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCount; j++) { Assert.AreEqual(matrix[i, j], i + j); } } for (var i = 0; i < rowCount; i++) { for (var j = 0; j < 3; j++) { Assert.AreEqual(matrix[i, matrix.Columns - j - 1], default(double)); } } }
public void Simple3() { var matrix = MatrixTest.GetTestMatrix(); var columnCount = matrix.Columns; var rowCount = matrix.Rows; matrix.AddRow(0, -1, -2); Assert.AreEqual(matrix.Columns, columnCount); Assert.AreEqual(matrix.Rows, rowCount + 1); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCount; j++) { Assert.AreEqual(matrix[i, j], i + j); } } Assert.AreEqual(matrix[rowCount, 0], 0); Assert.AreEqual(matrix[rowCount, 1], -1); Assert.AreEqual(matrix[rowCount, 2], -2); Assert.AreEqual(matrix[rowCount, 3], 0); Assert.AreEqual(matrix[rowCount, 4], 0); }
public void ExceptionNullOperatorPlus2() { var matrix = MatrixTest.GetTestMatrix(); Matrix newMatrix; Assert.Throws <ArgumentNullException>(() => newMatrix = matrix + null); }
public void ExceptionInvalidArrayLength1() { var matrix = MatrixTest.GetTestMatrix(); var array = new double[matrix.Rows * matrix.Columns - 1]; matrix.CopyTo(array, 0); }
public void Simple() { var matrix = new Matrix(5, 5); Assert.IsFalse(matrix.IsReadOnly); matrix = MatrixTest.GetTestMatrix(); Assert.IsFalse(matrix.IsReadOnly); }
public void ExceptionDifferentRowSizesLarger() { var matrix1 = MatrixTest.GetTestMatrix(); var matrix2 = GetTestMinusMatrix(); // Add a row to make the row sizes different matrix2.AddRow(); matrix1.Concatenate(matrix2); }
public void ExceptionDifferentRowSizesSmaller() { var matrix1 = MatrixTest.GetTestMatrix(); var matrix2 = GetTestMinusMatrix(); // Add a row to make the row sizes different matrix2.DeleteRow(0); Assert.Throws <ArgumentException>(() => matrix1.Concatenate(matrix2)); }
public void Simple() { var d = new Dictionary <Matrix, string>(); for (var i = 0; i < 10; i++) { var test = MatrixTest.GetTestMatrix(); Assert.IsFalse(d.ContainsKey(test)); d.Add(test, null); } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var newMatrix = SerializeUtil.BinarySerializeDeserialize(matrix); Assert.AreNotSame(matrix, newMatrix); Assert.AreEqual(matrix.Rows, newMatrix.Rows); Assert.AreEqual(matrix.Columns, newMatrix.Columns); Assert.IsTrue(matrix.Equals(newMatrix)); }
public void ExceptionIncompatibleMatrices() { IMathematicalMatrix matrix1 = new Matrix(2, 3); matrix1[0, 0] = 1; matrix1[0, 1] = 2; matrix1[0, 2] = -4; matrix1[1, 0] = 0; matrix1[1, 1] = 3; matrix1[1, 2] = -1; IMathematicalMatrix matrix2 = MatrixTest.GetTestMatrix(); matrix1.Add(matrix2); }
public void ExceptionIncompatibleMatrices() { var matrix1 = new Matrix(2, 3); matrix1[0, 0] = 1; matrix1[0, 1] = 2; matrix1[0, 2] = -4; matrix1[1, 0] = 0; matrix1[1, 1] = 3; matrix1[1, 2] = -1; var matrix2 = MatrixTest.GetTestMatrix(); matrix1.Subtract(matrix2); }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.IsTrue(matrix.Contains(i + j)); } } Assert.IsFalse(matrix.Contains(-5)); }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); matrix.Clear(); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.AreEqual(matrix[i, j], 0); } } }
public void ExceptionIncompatibleMatrices2() { IMathematicalMatrix matrix1 = new Matrix(2, 3); matrix1[0, 0] = 1; matrix1[0, 1] = 2; matrix1[0, 2] = -4; matrix1[1, 0] = 0; matrix1[1, 1] = 3; matrix1[1, 2] = -1; IMathematicalMatrix matrix2 = MatrixTest.GetTestMatrix(); Assert.Throws <ArgumentException>(() => matrix1.Subtract(matrix2)); }
public void Simple() { var visitor = new TrackingVisitor <double>(); var matrix = MatrixTest.GetTestMatrix(); matrix.AcceptVisitor(visitor); Assert.AreEqual(visitor.TrackingList.Count, matrix.Rows * matrix.Columns); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.IsTrue(visitor.TrackingList.Contains(i + j)); } } }
public void Smaller() { var matrix = MatrixTest.GetTestMatrix(); matrix.Resize(2, 2); Assert.AreEqual(matrix.Columns, 2); Assert.AreEqual(matrix.Rows, 2); for (var i = 0; i < 2; i++) { for (var j = 0; j < 2; j++) { Assert.AreEqual(matrix[i, j], i + j); } } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var clone = matrix.Clone(); Assert.AreEqual(matrix.Rows, clone.Rows); Assert.AreEqual(matrix.Columns, clone.Columns); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.AreEqual(matrix[i, j], clone[i, j]); } } }
public void InterfaceClone() { var matrix = MatrixTest.GetTestMatrix(); var clone = (Matrix)((ICloneable)matrix).Clone(); Assert.AreEqual(matrix.Rows, clone.Rows); Assert.AreEqual(matrix.Columns, clone.Columns); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.AreEqual(matrix[i, j], clone[i, j]); } } }
public void Simple() { var matrix = MatrixTest.GetTestMatrix(); var array = new double[matrix.Rows * matrix.Columns]; matrix.CopyTo(array, 0); var list = new List <double>(array); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { Assert.IsTrue(list.Contains(i + j)); } } }
public void ColumnArbitraryInterface() { IMathematicalMatrix matrix = MatrixTest.GetTestMatrix(); matrix.MultiplyColumn(3, 3); for (var i = 0; i < matrix.Rows; i++) { for (var j = 0; j < matrix.Columns; j++) { if (j == 3) { Assert.AreEqual(matrix[i, j], 3 * (i + j)); } else { Assert.AreEqual(matrix[i, j], i + j); } } } }