Browse Source

Tests: replace matrix structural tests with theory (part 3) - Column

pull/47/head
Christoph Ruegg 14 years ago
parent
commit
5d7fc8e67e
  1. 149
      src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs
  2. 8
      src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
  3. 149
      src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs
  4. 8
      src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
  5. 149
      src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs
  6. 8
      src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
  7. 91
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
  8. 138
      src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs
  9. 8
      src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs

149
src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs

@ -36,155 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Can get a column of a matrix.
/// </summary>
/// <param name="colIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1));
}
/// <summary>
/// Get column with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(matrix.ColumnCount));
}
/// <summary>
/// Can get a column into a result vector.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumnIntoResult(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = CreateVector(matrix.RowCount);
matrix.Column(colIndex, col);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column when result vector is <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void GetColumnWhenResultIsNullThrowsArgumentNullException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentNullException>(() => matrix.Column(0, null));
}
/// <summary>
/// Get a column into result vector with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1, column));
}
/// <summary>
/// Get a column into result with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Row(matrix.ColumnCount, column));
}
/// <summary>
/// Can get a column with range.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="start">Start index.</param>
/// <param name="length">Column length.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetColumnWithRange(int colIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex, start, length);
Assert.AreEqual(length, col.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j - start]);
}
}
/// <summary>
/// Get a column range into a result vector when length is zero throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var col = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, 0, col));
}
/// <summary>
/// Get a column range into too small result vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.RowCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, matrix.RowCount, result));
}
/// <summary>
/// Can set a row.
/// </summary>

8
src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs

@ -202,13 +202,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
}
/// <summary>
/// <c>CreateVector</c> throws <c>ArgumentException</c> if size is not positive.
/// <c>CreateVector</c> throws <c>ArgumentOutOfRangeException</c> if size is not positive.
/// </summary>
[Test]
public void SizeIsNotPositiveThrowsArgumentException()
public void SizeIsNotPositiveThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentException>(() => CreateVector(-1));
Assert.Throws<ArgumentException>(() => CreateVector(0));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(0));
}
/// <summary>

149
src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs

@ -36,155 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Can get a column of a matrix.
/// </summary>
/// <param name="colIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1));
}
/// <summary>
/// Get column with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(matrix.ColumnCount));
}
/// <summary>
/// Can get a column into a result vector.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumnIntoResult(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = CreateVector(matrix.RowCount);
matrix.Column(colIndex, col);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column when result vector is <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void GetColumnWhenResultIsNullThrowsArgumentNullException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentNullException>(() => matrix.Column(0, null));
}
/// <summary>
/// Get a column into result vector with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1, column));
}
/// <summary>
/// Get a column into result with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Row(matrix.ColumnCount, column));
}
/// <summary>
/// Can get a column with range.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="start">Start index.</param>
/// <param name="length">Column length.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetColumnWithRange(int colIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex, start, length);
Assert.AreEqual(length, col.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j - start]);
}
}
/// <summary>
/// Get a column range into a result vector when length is zero throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var col = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, 0, col));
}
/// <summary>
/// Get a column range into too small result vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.RowCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, matrix.RowCount, result));
}
/// <summary>
/// Can set a row.
/// </summary>

8
src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs

@ -202,13 +202,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
}
/// <summary>
/// <c>CreateVector</c> throws <c>ArgumentException</c> if size is not positive.
/// <c>CreateVector</c> throws <c>ArgumentOutOfRangeException</c> if size is not positive.
/// </summary>
[Test]
public void SizeIsNotPositiveThrowsArgumentException()
public void SizeIsNotPositiveThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentException>(() => CreateVector(-1));
Assert.Throws<ArgumentException>(() => CreateVector(0));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(0));
}
/// <summary>

149
src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs

@ -35,155 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Can get a column of a matrix.
/// </summary>
/// <param name="colIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1));
}
/// <summary>
/// Get column with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(matrix.ColumnCount));
}
/// <summary>
/// Can get a column into a result vector.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumnIntoResult(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = CreateVector(matrix.RowCount);
matrix.Column(colIndex, col);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column when result vector is <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void GetColumnWhenResultIsNullThrowsArgumentNullException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentNullException>(() => matrix.Column(0, null));
}
/// <summary>
/// Get a column into result vector with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1, column));
}
/// <summary>
/// Get a column into result with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Row(matrix.ColumnCount, column));
}
/// <summary>
/// Can get a column with range.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="start">Start index.</param>
/// <param name="length">Column length.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetColumnWithRange(int colIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex, start, length);
Assert.AreEqual(length, col.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j - start]);
}
}
/// <summary>
/// Get a column range into a result vector when length is zero throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var col = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, 0, col));
}
/// <summary>
/// Get a column range into too small result vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.RowCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, matrix.RowCount, result));
}
/// <summary>
/// Can set a row.
/// </summary>

8
src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs

@ -200,13 +200,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
}
/// <summary>
/// <c>CreateVector</c> throws <c>ArgumentException</c> if size is not positive.
/// <c>CreateVector</c> throws <c>ArgumentOutOfRangeException</c> if size is not positive.
/// </summary>
[Test]
public void SizeIsNotPositiveThrowsArgumentException()
public void SizeIsNotPositiveThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentException>(() => CreateVector(-1));
Assert.Throws<ArgumentException>(() => CreateVector(0));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(0));
}
/// <summary>

91
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs

@ -217,5 +217,96 @@
Assert.That(() => matrix.Row(0, 0, matrix.ColumnCount, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public void CanGetColumn(Matrix<T> matrix)
{
// First Column
var firstcol = matrix.Column(0);
Assert.That(firstcol.Count, Is.EqualTo(matrix.RowCount));
for (var i = 0; i < matrix.RowCount; i++)
{
Assert.AreEqual(matrix[i, 0], firstcol[i]);
}
// Last Column
var lastcol = matrix.Column(matrix.ColumnCount - 1);
Assert.That(lastcol.Count, Is.EqualTo(matrix.RowCount));
for (var i = 0; i < matrix.RowCount; i++)
{
Assert.AreEqual(matrix[i, matrix.ColumnCount - 1], lastcol[i]);
}
// Invalid Columns
Assert.That(() => { matrix.Column(-1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Column(matrix.ColumnCount); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public void CanGetColumnIntoResult(Matrix<T> matrix)
{
var col = CreateVector(matrix.RowCount);
matrix.Column(0, col);
for (var i = 0; i < matrix.RowCount; i++)
{
Assert.AreEqual(matrix[i, 0], col[i]);
}
Assert.That(() => matrix.Column(0, null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.Column(-1, col), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Column(matrix.ColumnCount, col), Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public virtual void CanGetColumnWithRange(Matrix<T> matrix)
{
// First Column, Rows 0..1
var firstcol = matrix.Column(0, 0, 2);
Assert.That(firstcol.Count, Is.EqualTo(2));
for (var i = 0; i < 2; i++)
{
Assert.AreEqual(matrix[i, 0], firstcol[i]);
}
// Second Column, Full Rows
var secondcol = matrix.Column(1, 0, matrix.RowCount);
Assert.That(secondcol.Count, Is.EqualTo(matrix.RowCount));
for (var i = 0; i < matrix.RowCount; i++)
{
Assert.AreEqual(matrix[i, 1], secondcol[i]);
}
// Last Column, Rows 1
var lastcol = matrix.Column(matrix.ColumnCount - 1, 1, 1);
Assert.That(lastcol.Count, Is.EqualTo(1));
for (var i = 0; i < 1; i++)
{
Assert.AreEqual(matrix[i + 1, matrix.ColumnCount - 1], lastcol[i]);
}
// Invalid Rows
Assert.That(() => { matrix.Column(-1, 0, 2); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Column(matrix.ColumnCount, 0, 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Column(0, -1, 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Column(0, 1, 0); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Column(0, 0, matrix.RowCount + 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public void CanGetColumnWithRangeIntoResult(Matrix<T> matrix)
{
var col = CreateVector(matrix.RowCount - 1);
matrix.Column(0, 1, matrix.RowCount - 1, col);
for (var i = 0; i < matrix.RowCount - 1; i++)
{
Assert.AreEqual(matrix[i + 1, 0], col[i]);
}
Assert.That(() => matrix.Column(0, 0, matrix.RowCount - 1, null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.Column(-1, 0, matrix.RowCount - 1, col), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Column(matrix.ColumnCount, 0, matrix.ColumnCount - 1, col), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Column(0, 0, matrix.RowCount, col), Throws.InstanceOf<ArgumentOutOfRangeException>());
}
}
}

138
src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs

@ -35,144 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can get a column of a matrix.
/// </summary>
/// <param name="colIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1));
}
/// <summary>
/// Get column with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(matrix.ColumnCount));
}
/// <summary>
/// Can get a column into a result vector.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumnIntoResult(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = CreateVector(matrix.RowCount);
matrix.Column(colIndex, col);
Assert.AreEqual(matrix.RowCount, col.Count);
for (var j = 0; j < matrix.RowCount; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j]);
}
}
/// <summary>
/// Get a column when result vector is <c>null</c> throws <c>ArgumentNullException</c>.
/// </summary>
[Test]
public void GetColumnWhenResultIsNullThrowsArgumentNullException()
{
var matrix = TestMatrices["Singular3x3"];
Assert.Throws<ArgumentNullException>(() => matrix.Column(0, null));
}
/// <summary>
/// Get a column into result vector with negative index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Column(-1, column));
}
/// <summary>
/// Get a column into result with overflowing row index throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
[Test]
public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException()
{
var matrix = TestMatrices["Singular3x3"];
var column = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Row(matrix.ColumnCount, column));
}
/// <summary>
/// Can get a column with range.
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="start">Start index.</param>
/// <param name="length">Column length.</param>
/// <param name="name">Matrix name.</param>
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetColumnWithRange(int colIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex, start, length);
Assert.AreEqual(length, col.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[j, colIndex], col[j - start]);
}
}
/// <summary>
/// Get a column range into a result vector when length is zero throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var col = CreateVector(matrix.RowCount);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, 0, col));
}
/// <summary>
/// Get a column range into too small result vector throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.RowCount - 1);
Assert.Throws<ArgumentException>(() => matrix.Column(0, 0, matrix.RowCount, result));
}
/// <summary>
/// Can set a row.
/// </summary>

8
src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs

@ -200,13 +200,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
}
/// <summary>
/// <c>CreateVector</c> throws <c>ArgumentException</c> if size is not positive.
/// <c>CreateVector</c> throws <c>ArgumentOutOfRangeException</c> if size is not positive.
/// </summary>
[Test]
public void SizeIsNotPositiveThrowsArgumentException()
public void SizeIsNotPositiveThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentException>(() => CreateVector(-1));
Assert.Throws<ArgumentException>(() => CreateVector(0));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(-1));
Assert.Throws<ArgumentOutOfRangeException>(() => CreateVector(0));
}
/// <summary>

Loading…
Cancel
Save