Browse Source

Tests: replace matrix structural tests with theory (part 2) - Row

la-knuth
Christoph Ruegg 14 years ago
parent
commit
de5d235f6f
  1. 12
      src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs
  2. 6
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  3. 12
      src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs
  4. 6
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  5. 12
      src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs
  6. 6
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  7. 16
      src/Numerics/LinearAlgebra/Generic/Matrix.cs
  8. 6
      src/Numerics/LinearAlgebra/Generic/Vector.cs
  9. 12
      src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs
  10. 6
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  11. 34
      src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs
  12. 34
      src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs
  13. 34
      src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs
  14. 72
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs
  15. 45
      src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs

12
src/Numerics/LinearAlgebra/Complex/DiagonalMatrix.cs

@ -747,7 +747,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Column(int columnIndex, int rowIndex, int length, Vector<Complex> result)
{
@ -773,12 +773,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.
@ -803,7 +803,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<Complex> result)
{
@ -829,12 +829,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.

6
src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs

@ -756,7 +756,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<Complex> result)
{
@ -782,12 +782,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
var rowPointers = _storage.RowPointers;

12
src/Numerics/LinearAlgebra/Complex32/DiagonalMatrix.cs

@ -747,7 +747,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Column(int columnIndex, int rowIndex, int length, Vector<Complex32> result)
{
@ -773,12 +773,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.
@ -803,7 +803,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<Complex32> result)
{
@ -829,12 +829,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.

6
src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs

@ -756,7 +756,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<Complex32> result)
{
@ -782,12 +782,12 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
var rowPointers = _storage.RowPointers;

12
src/Numerics/LinearAlgebra/Double/DiagonalMatrix.cs

@ -741,7 +741,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Column(int columnIndex, int rowIndex, int length, Vector<double> result)
{
@ -767,12 +767,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.
@ -797,7 +797,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<double> result)
{
@ -823,12 +823,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.

6
src/Numerics/LinearAlgebra/Double/SparseMatrix.cs

@ -754,7 +754,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<double> result)
{
@ -780,12 +780,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
var rowPointers = _storage.RowPointers;

16
src/Numerics/LinearAlgebra/Generic/Matrix.cs

@ -339,7 +339,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <item><paramref name="columnIndex"/> is negative,
/// or greater than or equal to the number of columns.</item>
/// <item><c>(columnIndex + length) &gt;= Columns.</c></item></list></exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
public virtual Vector<T> Row(int rowIndex, int columnIndex, int length)
{
var ret = CreateVector(length);
@ -361,7 +361,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public virtual void Row(int rowIndex, int columnIndex, int length, Vector<T> result)
{
@ -387,12 +387,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
for (int i = columnIndex, j = 0; i < columnIndex + length; i++, j++)
@ -443,7 +443,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// or greater than or equal to the number of rows.</item>
/// <item><c>(rowIndex + length) &gt;= Rows.</c></item></list>
/// </exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
public virtual Vector<T> Column(int columnIndex, int rowIndex, int length)
{
var result = CreateVector(length);
@ -465,7 +465,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public virtual void Column(int columnIndex, int rowIndex, int length, Vector<T> result)
{
@ -491,12 +491,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
for (int i = rowIndex, j = 0; i < rowIndex + length; i++, j++)

6
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -66,14 +66,14 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <param name="size">
/// The size of the <strong>Vector</strong> to construct.
/// </param>
/// <exception cref="ArgumentException">
/// <exception cref="ArgumentOutOfRangeException">
/// If <paramref name="size"/> is less than one.
/// </exception>
protected Vector(int size)
{
if (size < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "size");
throw new ArgumentOutOfRangeException("size", Resources.ArgumentMustBePositive);
}
Count = size;
@ -91,7 +91,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>Gets or sets the value at the given <paramref name="index"/>.</summary>
/// <param name="index">The index of the value to get or set.</param>
/// <returns>The value of the vector at the given <paramref name="index"/>.</returns>
/// <exception cref="IndexOutOfRangeException">If <paramref name="index"/> is negative or
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is negative or
/// greater than the size of the vector.</exception>
public virtual T this[int index]
{

12
src/Numerics/LinearAlgebra/Single/DiagonalMatrix.cs

@ -741,7 +741,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Column(int columnIndex, int rowIndex, int length, Vector<float> result)
{
@ -767,12 +767,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.
@ -797,7 +797,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<float> result)
{
@ -823,12 +823,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
// Clear the result and copy the diagonal entry.

6
src/Numerics/LinearAlgebra/Single/SparseMatrix.cs

@ -754,7 +754,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// or greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> + <paramref name="length"/>
/// is greater than or equal to the number of rows.</exception>
/// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentOutOfRangeException">If <strong>result.Count &lt; length</strong>.</exception>
public override void Row(int rowIndex, int columnIndex, int length, Vector<float> result)
{
@ -780,12 +780,12 @@ namespace MathNet.Numerics.LinearAlgebra.Single
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
throw new ArgumentOutOfRangeException("length", Resources.ArgumentMustBePositive);
}
if (result.Count < length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result");
throw new ArgumentOutOfRangeException("result", Resources.ArgumentVectorsSameLength);
}
var rowPointers = _storage.RowPointers;

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

@ -36,40 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can get a row at specific start position and length of a matrix into a vector.
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="start">Column start.</param>
/// <param name="length">Row 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 CanGetRowWithRange(int rowIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex, start, length);
Assert.AreEqual(length, row.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[rowIndex, j], row[j - start]);
}
}
/// <summary>
/// Get a row of a matrix at specific start position and zero length throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>

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

@ -36,40 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can get a row at specific start position and length of a matrix into a vector.
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="start">Column start.</param>
/// <param name="length">Row 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 CanGetRowWithRange(int rowIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex, start, length);
Assert.AreEqual(length, row.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[rowIndex, j], row[j - start]);
}
}
/// <summary>
/// Get a row of a matrix at specific start position and zero length throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>

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

@ -35,40 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can get a row at specific start position and length of a matrix into a vector.
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="start">Column start.</param>
/// <param name="length">Row 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 CanGetRowWithRange(int rowIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex, start, length);
Assert.AreEqual(length, row.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[rowIndex, j], row[j - start]);
}
}
/// <summary>
/// Get a row of a matrix at specific start position and zero length throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <summary>
/// Get a row at specific start position and length of a matrix into a too small vector throws <c>ArgumentException</c>.
/// </summary>

72
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs

@ -126,16 +126,25 @@
}
[Theory, Timeout(200)]
public void CanGetRow(Matrix<T> matrix, [Values(0, 1, 1000)]int rowIndex)
public void CanGetRow(Matrix<T> matrix)
{
var actualRow = Math.Min(rowIndex, matrix.RowCount - 1);
var row = matrix.Row(actualRow);
Assert.That(row.Count, Is.EqualTo(matrix.ColumnCount));
// First Row
var firstrow = matrix.Row(0);
Assert.That(firstrow.Count, Is.EqualTo(matrix.ColumnCount));
for (var j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(matrix[actualRow, j], row[j]);
Assert.AreEqual(matrix[0, j], firstrow[j]);
}
// Last Row
var lastrow = matrix.Row(matrix.RowCount - 1);
Assert.That(lastrow.Count, Is.EqualTo(matrix.ColumnCount));
for (var j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(matrix[matrix.RowCount - 1, j], lastrow[j]);
}
// Invalid Rows
Assert.That(() => { matrix.Row(-1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Row(matrix.RowCount); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
}
@ -155,5 +164,58 @@
Assert.That(() => matrix.Row(-1, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Row(matrix.RowCount, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public virtual void CanGetRowWithRange(Matrix<T> matrix)
{
// First Row, Columns 0..1
var firstrow = matrix.Row(0, 0, 2);
Assert.That(firstrow.Count, Is.EqualTo(2));
for (var j = 0; j < 2; j++)
{
Assert.AreEqual(matrix[0, j], firstrow[j]);
}
// Second Row, Full Columns
var secondrow = matrix.Row(1, 0, matrix.ColumnCount);
Assert.That(secondrow.Count, Is.EqualTo(matrix.ColumnCount));
for (var j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(matrix[1, j], secondrow[j]);
}
// Last Row, Columns 1
var lastrow = matrix.Row(matrix.RowCount - 1, 1, 1);
Assert.That(lastrow.Count, Is.EqualTo(1));
for (var j = 0; j < 1; j++)
{
Assert.AreEqual(matrix[matrix.RowCount - 1, j + 1], lastrow[j]);
}
// Invalid Rows
Assert.That(() => { matrix.Row(-1, 0, 2); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Row(matrix.RowCount, 0, 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Row(0, -1, 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Row(0, 1, 0); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => { matrix.Row(0, 0, matrix.ColumnCount + 1); }, Throws.InstanceOf<ArgumentOutOfRangeException>());
}
[Theory, Timeout(200)]
public void CanGetRowWithRangeIntoResult(Matrix<T> matrix)
{
var row = CreateVector(matrix.ColumnCount - 1);
matrix.Row(0, 1, matrix.ColumnCount - 1, row);
for (var j = 0; j < matrix.ColumnCount - 1; j++)
{
Assert.AreEqual(matrix[0, j + 1], row[j]);
}
Assert.That(() => matrix.Row(0, 0, matrix.ColumnCount - 1, null), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => matrix.Row(-1, 0, matrix.ColumnCount - 1, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Row(matrix.RowCount, 0, matrix.ColumnCount - 1, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
Assert.That(() => matrix.Row(0, 0, matrix.ColumnCount, row), Throws.InstanceOf<ArgumentOutOfRangeException>());
}
}
}

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

@ -35,51 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary>
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can get a row at specific start position and length of a matrix into a vector.
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="start">Column start.</param>
/// <param name="length">Row 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 CanGetRowWithRange(int rowIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex, start, length);
Assert.AreEqual(length, row.Count);
for (var j = start; j < start + length; j++)
{
Assert.AreEqual(matrix[rowIndex, j], row[j - start]);
}
}
/// <summary>
/// Get a row of a matrix at specific start position and zero length throws <c>ArgumentException</c>.
/// </summary>
[Test]
public void GetRowWithRangeIntoResultWhenLengthIsZeroThrowsArgumentException()
{
var matrix = TestMatrices["Singular3x3"];
var result = CreateVector(matrix.ColumnCount);
Assert.Throws<ArgumentException>(() => matrix.Row(0, 0, 0, result));
}
/// <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>

Loading…
Cancel
Save