From 5d7fc8e67e4cf5b2c108f415636452e291573ef2 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 4 Aug 2012 00:37:44 +0200 Subject: [PATCH] Tests: replace matrix structural tests with theory (part 3) - Column --- .../LinearAlgebraTests/Complex/MatrixTests.cs | 149 ------------------ .../LinearAlgebraTests/Complex/VectorTests.cs | 8 +- .../Complex32/MatrixTests.cs | 149 ------------------ .../Complex32/VectorTests.cs | 8 +- .../LinearAlgebraTests/Double/MatrixTests.cs | 149 ------------------ .../LinearAlgebraTests/Double/VectorTests.cs | 8 +- .../MatrixStructureTheory.cs | 91 +++++++++++ .../LinearAlgebraTests/Single/MatrixTests.cs | 138 ---------------- .../LinearAlgebraTests/Single/VectorTests.cs | 8 +- 9 files changed, 107 insertions(+), 601 deletions(-) diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs index dc1ff902..8c5e5066 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs @@ -36,155 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex /// public abstract partial class MatrixTests : MatrixLoader { - /// - /// Get a row at specific start position and length of a matrix into a too small vector throws ArgumentException. - /// - [Test] - public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.ColumnCount - 1); - Assert.Throws(() => matrix.Row(0, 0, 0, result)); - } - - /// - /// Can get a column of a matrix. - /// - /// Row index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(-1)); - } - - /// - /// Get column with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(matrix.ColumnCount)); - } - - /// - /// Can get a column into a result vector. - /// - /// Column index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column when result vector is null throws ArgumentNullException. - /// - [Test] - public void GetColumnWhenResultIsNullThrowsArgumentNullException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(0, null)); - } - - /// - /// Get a column into result vector with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.ColumnCount); - Assert.Throws(() => matrix.Column(-1, column)); - } - - /// - /// Get a column into result with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Row(matrix.ColumnCount, column)); - } - - /// - /// Can get a column with range. - /// - /// Column index. - /// Start index. - /// Column length. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column range into a result vector when length is zero throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var col = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Column(0, 0, 0, col)); - } - - /// - /// Get a column range into too small result vector throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.RowCount - 1); - Assert.Throws(() => matrix.Column(0, 0, matrix.RowCount, result)); - } - /// /// Can set a row. /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs index 75ca768d..f0188b44 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs @@ -202,13 +202,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex } /// - /// CreateVector throws ArgumentException if size is not positive. + /// CreateVector throws ArgumentOutOfRangeException if size is not positive. /// [Test] - public void SizeIsNotPositiveThrowsArgumentException() + public void SizeIsNotPositiveThrowsArgumentOutOfRangeException() { - Assert.Throws(() => CreateVector(-1)); - Assert.Throws(() => CreateVector(0)); + Assert.Throws(() => CreateVector(-1)); + Assert.Throws(() => CreateVector(0)); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs index e5855c87..1769589d 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixTests.cs @@ -36,155 +36,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 /// public abstract partial class MatrixTests : MatrixLoader { - /// - /// Get a row at specific start position and length of a matrix into a too small vector throws ArgumentException. - /// - [Test] - public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.ColumnCount - 1); - Assert.Throws(() => matrix.Row(0, 0, 0, result)); - } - - /// - /// Can get a column of a matrix. - /// - /// Row index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(-1)); - } - - /// - /// Get column with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(matrix.ColumnCount)); - } - - /// - /// Can get a column into a result vector. - /// - /// Column index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column when result vector is null throws ArgumentNullException. - /// - [Test] - public void GetColumnWhenResultIsNullThrowsArgumentNullException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(0, null)); - } - - /// - /// Get a column into result vector with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.ColumnCount); - Assert.Throws(() => matrix.Column(-1, column)); - } - - /// - /// Get a column into result with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Row(matrix.ColumnCount, column)); - } - - /// - /// Can get a column with range. - /// - /// Column index. - /// Start index. - /// Column length. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column range into a result vector when length is zero throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var col = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Column(0, 0, 0, col)); - } - - /// - /// Get a column range into too small result vector throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.RowCount - 1); - Assert.Throws(() => matrix.Column(0, 0, matrix.RowCount, result)); - } - /// /// Can set a row. /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs index 6fb915d1..0a478666 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs @@ -202,13 +202,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 } /// - /// CreateVector throws ArgumentException if size is not positive. + /// CreateVector throws ArgumentOutOfRangeException if size is not positive. /// [Test] - public void SizeIsNotPositiveThrowsArgumentException() + public void SizeIsNotPositiveThrowsArgumentOutOfRangeException() { - Assert.Throws(() => CreateVector(-1)); - Assert.Throws(() => CreateVector(0)); + Assert.Throws(() => CreateVector(-1)); + Assert.Throws(() => CreateVector(0)); } /// diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs index 19a6e83a..9ace2619 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs @@ -35,155 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double /// public abstract partial class MatrixTests : MatrixLoader { - /// - /// Get a row at specific start position and length of a matrix into a too small vector throws ArgumentException. - /// - [Test] - public void GetRowWithRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.ColumnCount - 1); - Assert.Throws(() => matrix.Row(0, 0, 0, result)); - } - - /// - /// Can get a column of a matrix. - /// - /// Row index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(-1)); - } - - /// - /// Get column with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(matrix.ColumnCount)); - } - - /// - /// Can get a column into a result vector. - /// - /// Column index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column when result vector is null throws ArgumentNullException. - /// - [Test] - public void GetColumnWhenResultIsNullThrowsArgumentNullException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(0, null)); - } - - /// - /// Get a column into result vector with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.ColumnCount); - Assert.Throws(() => matrix.Column(-1, column)); - } - - /// - /// Get a column into result with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Row(matrix.ColumnCount, column)); - } - - /// - /// Can get a column with range. - /// - /// Column index. - /// Start index. - /// Column length. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column range into a result vector when length is zero throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var col = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Column(0, 0, 0, col)); - } - - /// - /// Get a column range into too small result vector throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.RowCount - 1); - Assert.Throws(() => matrix.Column(0, 0, matrix.RowCount, result)); - } - /// /// Can set a row. /// diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs index ee821600..75fc6035 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs @@ -200,13 +200,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } /// - /// CreateVector throws ArgumentException if size is not positive. + /// CreateVector throws ArgumentOutOfRangeException if size is not positive. /// [Test] - public void SizeIsNotPositiveThrowsArgumentException() + public void SizeIsNotPositiveThrowsArgumentOutOfRangeException() { - Assert.Throws(() => CreateVector(-1)); - Assert.Throws(() => CreateVector(0)); + Assert.Throws(() => CreateVector(-1)); + Assert.Throws(() => CreateVector(0)); } /// diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs index 30effde4..75655109 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs @@ -217,5 +217,96 @@ Assert.That(() => matrix.Row(0, 0, matrix.ColumnCount, row), Throws.InstanceOf()); } + [Theory, Timeout(200)] + public void CanGetColumn(Matrix 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()); + Assert.That(() => { matrix.Column(matrix.ColumnCount); }, Throws.InstanceOf()); + } + + [Theory, Timeout(200)] + public void CanGetColumnIntoResult(Matrix 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()); + Assert.That(() => matrix.Column(-1, col), Throws.InstanceOf()); + Assert.That(() => matrix.Column(matrix.ColumnCount, col), Throws.InstanceOf()); + } + + [Theory, Timeout(200)] + public virtual void CanGetColumnWithRange(Matrix 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()); + Assert.That(() => { matrix.Column(matrix.ColumnCount, 0, 1); }, Throws.InstanceOf()); + Assert.That(() => { matrix.Column(0, -1, 1); }, Throws.InstanceOf()); + Assert.That(() => { matrix.Column(0, 1, 0); }, Throws.InstanceOf()); + Assert.That(() => { matrix.Column(0, 0, matrix.RowCount + 1); }, Throws.InstanceOf()); + } + + [Theory, Timeout(200)] + public void CanGetColumnWithRangeIntoResult(Matrix 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()); + Assert.That(() => matrix.Column(-1, 0, matrix.RowCount - 1, col), Throws.InstanceOf()); + Assert.That(() => matrix.Column(matrix.ColumnCount, 0, matrix.ColumnCount - 1, col), Throws.InstanceOf()); + Assert.That(() => matrix.Column(0, 0, matrix.RowCount, col), Throws.InstanceOf()); + } } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs index a1c91ddd..48bb76ee 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixTests.cs @@ -35,144 +35,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single /// public abstract partial class MatrixTests : MatrixLoader { - /// - /// Can get a column of a matrix. - /// - /// Row index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(-1)); - } - - /// - /// Get column with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(matrix.ColumnCount)); - } - - /// - /// Can get a column into a result vector. - /// - /// Column index. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column when result vector is null throws ArgumentNullException. - /// - [Test] - public void GetColumnWhenResultIsNullThrowsArgumentNullException() - { - var matrix = TestMatrices["Singular3x3"]; - Assert.Throws(() => matrix.Column(0, null)); - } - - /// - /// Get a column into result vector with negative index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithNegativeIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.ColumnCount); - Assert.Throws(() => matrix.Column(-1, column)); - } - - /// - /// Get a column into result with overflowing row index throws ArgumentOutOfRangeException. - /// - [Test] - public void GetColumnIntoResultWithOverflowingRowIndexThrowsArgumentOutOfRangeException() - { - var matrix = TestMatrices["Singular3x3"]; - var column = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Row(matrix.ColumnCount, column)); - } - - /// - /// Can get a column with range. - /// - /// Column index. - /// Start index. - /// Column length. - /// Matrix name. - [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]); - } - } - - /// - /// Get a column range into a result vector when length is zero throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoResultWhenLengthIsZeroThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var col = CreateVector(matrix.RowCount); - Assert.Throws(() => matrix.Column(0, 0, 0, col)); - } - - /// - /// Get a column range into too small result vector throws ArgumentException. - /// - [Test] - public void GetColumnRangeIntoTooSmallResultVectorThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var result = CreateVector(matrix.RowCount - 1); - Assert.Throws(() => matrix.Column(0, 0, matrix.RowCount, result)); - } - /// /// Can set a row. /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs index 14c4e92d..9fff4251 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs @@ -200,13 +200,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single } /// - /// CreateVector throws ArgumentException if size is not positive. + /// CreateVector throws ArgumentOutOfRangeException if size is not positive. /// [Test] - public void SizeIsNotPositiveThrowsArgumentException() + public void SizeIsNotPositiveThrowsArgumentOutOfRangeException() { - Assert.Throws(() => CreateVector(-1)); - Assert.Throws(() => CreateVector(0)); + Assert.Throws(() => CreateVector(-1)); + Assert.Throws(() => CreateVector(0)); } ///