Browse Source

LA: Adapt parsing and unit tests to modified string formatting

pull/112/head
Christoph Ruegg 14 years ago
parent
commit
b4ee5ed34f
  1. 2
      src/Numerics/Control.cs
  2. 53
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  3. 1
      src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
  4. 52
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  5. 52
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  6. 1
      src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
  7. 52
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  8. 36
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  9. 1
      src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
  10. 35
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  11. 18
      src/Numerics/LinearAlgebra/Generic/Matrix.BCL.cs
  12. 8
      src/Numerics/LinearAlgebra/Generic/Matrix.cs
  13. 19
      src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs
  14. 36
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  15. 1
      src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
  16. 41
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  17. 1
      src/Numerics/Statistics/Statistics.cs
  18. 41
      src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTest.TextHandling.cs
  19. 41
      src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.TextHandling.cs
  20. 20
      src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
  21. 41
      src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs
  22. 41
      src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs
  23. 20
      src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
  24. 4
      src/UnitTests/LinearAlgebraTests/Double/DenseMatrixTests.cs
  25. 40
      src/UnitTests/LinearAlgebraTests/Double/DenseVectorTest.TextHandling.cs
  26. 40
      src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.TextHandling.cs
  27. 18
      src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
  28. 40
      src/UnitTests/LinearAlgebraTests/Single/DenseVectorTest.TextHandling.cs
  29. 40
      src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.TextHandling.cs
  30. 20
      src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs

2
src/Numerics/Control.cs

@ -30,8 +30,8 @@
namespace MathNet.Numerics namespace MathNet.Numerics
{ {
using System;
using Algorithms.LinearAlgebra; using Algorithms.LinearAlgebra;
using System;
/// <summary> /// <summary>
/// Sets parameters for the library. /// Sets parameters for the library.

53
src/Numerics/LinearAlgebra/Complex/DenseVector.cs

@ -28,12 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
namespace MathNet.Numerics.LinearAlgebra.Complex namespace MathNet.Numerics.LinearAlgebra.Complex
{ {
using Distributions; using Distributions;
using Generic; using Generic;
using NumberTheory;
using Storage; using Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -758,39 +756,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new Complex[(tokens.Count + 1) >> 1]; var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = new List<Complex>();
foreach (string strongToken in strongTokens)
{ {
if (token == null || token.Value == textInfo.ListSeparator) var weakTokens = strongToken.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
string current = string.Empty;
for (int i = 0; i < weakTokens.Length; i++)
{ {
throw new FormatException(); current += weakTokens[i];
if (current.EndsWith("+") || current.EndsWith("-") || current.StartsWith("(") && !current.EndsWith(")"))
{
continue;
}
var ahead = i < weakTokens.Length - 1 ? weakTokens[i + 1] : string.Empty;
if (ahead.StartsWith("+") || ahead.StartsWith("-"))
{
continue;
}
data.Add(current.ToComplex(formatProvider));
current = string.Empty;
} }
if (current != string.Empty)
data[i] = token.Value.ToComplex(formatProvider);
token = token.Next;
if (token != null)
{ {
token = token.Next; throw new FormatException();
} }
} }
if (data.Count == 0)
return new DenseVector(data); {
throw new FormatException();
}
return new DenseVector(data.ToArray());
} }
/// <summary> /// <summary>

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

@ -37,7 +37,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Numerics; using System.Numerics;
using Threading;
/// <summary> /// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format. /// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.

52
src/Numerics/LinearAlgebra/Complex/SparseVector.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Complex namespace MathNet.Numerics.LinearAlgebra.Complex
{ {
using Generic; using Generic;
using NumberTheory;
using Storage; using Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -941,39 +940,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new Complex[(tokens.Count + 1) >> 1]; var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = new List<Complex>();
foreach (string strongToken in strongTokens)
{ {
if (token == null || token.Value == textInfo.ListSeparator) var weakTokens = strongToken.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
string current = string.Empty;
for (int i = 0; i < weakTokens.Length; i++)
{ {
throw new FormatException(); current += weakTokens[i];
if (current.EndsWith("+") || current.EndsWith("-") || current.StartsWith("(") && !current.EndsWith(")"))
{
continue;
}
var ahead = i < weakTokens.Length - 1 ? weakTokens[i + 1] : string.Empty;
if (ahead.StartsWith("+") || ahead.StartsWith("-"))
{
continue;
}
data.Add(current.ToComplex(formatProvider));
current = string.Empty;
} }
if (current != string.Empty)
data[i] = token.Value.ToComplex(formatProvider);
token = token.Next;
if (token != null)
{ {
token = token.Next; throw new FormatException();
} }
} }
if (data.Count == 0)
return new SparseVector(data); {
throw new FormatException();
}
return new SparseVector(data.ToArray());
} }
/// <summary> /// <summary>

52
src/Numerics/LinearAlgebra/Complex32/DenseVector.cs

@ -32,7 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{ {
using Distributions; using Distributions;
using Generic; using Generic;
using NumberTheory;
using Numerics; using Numerics;
using Storage; using Storage;
using System; using System;
@ -757,39 +756,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new Complex32[(tokens.Count + 1) >> 1]; var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = new List<Complex32>();
foreach (string strongToken in strongTokens)
{ {
if (token == null || token.Value == textInfo.ListSeparator) var weakTokens = strongToken.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
string current = string.Empty;
for (int i = 0; i < weakTokens.Length; i++)
{ {
throw new FormatException(); current += weakTokens[i];
if (current.EndsWith("+") || current.EndsWith("-") || current.StartsWith("(") && !current.EndsWith(")"))
{
continue;
}
var ahead = i < weakTokens.Length - 1 ? weakTokens[i + 1] : string.Empty;
if (ahead.StartsWith("+") || ahead.StartsWith("-"))
{
continue;
}
data.Add(current.ToComplex32(formatProvider));
current = string.Empty;
} }
if (current != string.Empty)
data[i] = token.Value.ToComplex32(formatProvider);
token = token.Next;
if (token != null)
{ {
token = token.Next; throw new FormatException();
} }
} }
if (data.Count == 0)
return new DenseVector(data); {
throw new FormatException();
}
return new DenseVector(data.ToArray());
} }
/// <summary> /// <summary>

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

@ -37,7 +37,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Threading;
/// <summary> /// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format. /// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.

52
src/Numerics/LinearAlgebra/Complex32/SparseVector.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Complex32 namespace MathNet.Numerics.LinearAlgebra.Complex32
{ {
using Generic; using Generic;
using NumberTheory;
using Numerics; using Numerics;
using Storage; using Storage;
using System; using System;
@ -941,39 +940,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new Complex32[(tokens.Count + 1) >> 1]; var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = new List<Complex32>();
foreach (string strongToken in strongTokens)
{ {
if (token == null || token.Value == textInfo.ListSeparator) var weakTokens = strongToken.Split(new[] { " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
string current = string.Empty;
for (int i = 0; i < weakTokens.Length; i++)
{ {
throw new FormatException(); current += weakTokens[i];
if (current.EndsWith("+") || current.EndsWith("-") || current.StartsWith("(") && !current.EndsWith(")"))
{
continue;
}
var ahead = i < weakTokens.Length - 1 ? weakTokens[i + 1] : string.Empty;
if (ahead.StartsWith("+") || ahead.StartsWith("-"))
{
continue;
}
data.Add(current.ToComplex32(formatProvider));
current = string.Empty;
} }
if (current != string.Empty)
data[i] = token.Value.ToComplex32(formatProvider);
token = token.Next;
if (token != null)
{ {
token = token.Next; throw new FormatException();
} }
} }
if (data.Count == 0)
return new SparseVector(data); {
throw new FormatException();
}
return new SparseVector(data.ToArray());
} }
/// <summary> /// <summary>

36
src/Numerics/LinearAlgebra/Double/DenseVector.cs

@ -32,11 +32,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{ {
using Distributions; using Distributions;
using Generic; using Generic;
using NumberTheory;
using Properties; using Properties;
using Storage; using Storage;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -852,38 +850,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new double[(tokens.Count + 1) >> 1]; var tokens = value.Split(new[] {formatProvider.GetTextInfo().ListSeparator, " ", "\t"}, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = tokens.Select(t => Double.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
{ if (data.Length == 0) throw new FormatException();
if (token == null || token.Value == textInfo.ListSeparator)
{
throw new FormatException();
}
data[i] = Double.Parse(token.Value, NumberStyles.Any, formatProvider);
token = token.Next;
if (token != null)
{
token = token.Next;
}
}
return new DenseVector(data); return new DenseVector(data);
} }

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

@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Threading;
/// <summary> /// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format. /// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.

35
src/Numerics/LinearAlgebra/Double/SparseVector.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.LinearAlgebra.Double namespace MathNet.Numerics.LinearAlgebra.Double
{ {
using Generic; using Generic;
using NumberTheory;
using Storage; using Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -974,38 +973,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new double[(tokens.Count + 1) >> 1]; var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = tokens.Select(t => Double.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
{ if (data.Length == 0) throw new FormatException();
if (token == null || token.Value == textInfo.ListSeparator)
{
throw new FormatException();
}
data[i] = Double.Parse(token.Value, NumberStyles.Any, formatProvider);
token = token.Next;
if (token != null)
{
token = token.Next;
}
}
return new SparseVector(data); return new SparseVector(data);
} }

18
src/Numerics/LinearAlgebra/Generic/Matrix.BCL.cs

@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this matrix. /// Returns a <see cref="System.String"/> that represents the content of this matrix.
/// </summary> /// </summary>
public string ToMatrixString(int maxRows, int maxColumns, IFormatProvider provider) public string ToMatrixString(int maxRows, int maxColumns, IFormatProvider provider = null)
{ {
return ToMatrixString(maxRows, maxColumns, 12, "G6", provider); return ToMatrixString(maxRows, maxColumns, 12, "G6", provider);
} }
@ -109,7 +109,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this matrix. /// Returns a <see cref="System.String"/> that represents the content of this matrix.
/// </summary> /// </summary>
public string ToMatrixString(int maxRows, int maxColumns, int padding, string format, IFormatProvider provider) public string ToMatrixString(int maxRows, int maxColumns, int padding, string format = null, IFormatProvider provider = null)
{ {
int rowN = RowCount <= maxRows ? RowCount : maxRows < 3 ? maxRows : maxRows - 1; int rowN = RowCount <= maxRows ? RowCount : maxRows < 3 ? maxRows : maxRows - 1;
bool rowDots = maxRows < RowCount; bool rowDots = maxRows < RowCount;
@ -123,10 +123,19 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
const string dots = "..."; const string dots = "...";
string pdots = "...".PadLeft(padding); string pdots = "...".PadLeft(padding);
if (format == null)
{
format = "G8";
}
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
for (var row = 0; row < rowN; row++) for (var row = 0; row < rowN; row++)
{ {
if (row > 0)
{
stringBuilder.Append(Environment.NewLine);
}
stringBuilder.Append(At(row, 0).ToString(format, provider).PadLeft(padding)); stringBuilder.Append(At(row, 0).ToString(format, provider).PadLeft(padding));
for (var column = 1; column < colN; column++) for (var column = 1; column < colN; column++)
{ {
@ -143,11 +152,11 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
stringBuilder.Append(At(row, ColumnCount - 1).ToString(format, provider).PadLeft(12)); stringBuilder.Append(At(row, ColumnCount - 1).ToString(format, provider).PadLeft(12));
} }
} }
stringBuilder.Append(Environment.NewLine);
} }
if (rowDots) if (rowDots)
{ {
stringBuilder.Append(Environment.NewLine);
stringBuilder.Append(pdots); stringBuilder.Append(pdots);
for (var column = 1; column < colN; column++) for (var column = 1; column < colN; column++)
{ {
@ -164,11 +173,11 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
stringBuilder.Append(pdots); stringBuilder.Append(pdots);
} }
} }
stringBuilder.Append(Environment.NewLine);
} }
if (rowLast) if (rowLast)
{ {
stringBuilder.Append(Environment.NewLine);
stringBuilder.Append(At(RowCount - 1, 0).ToString(format, provider).PadLeft(padding)); stringBuilder.Append(At(RowCount - 1, 0).ToString(format, provider).PadLeft(padding));
for (var column = 1; column < colN; column++) for (var column = 1; column < colN; column++)
{ {
@ -185,7 +194,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
stringBuilder.Append(At(RowCount - 1, ColumnCount - 1).ToString(format, provider).PadLeft(padding)); stringBuilder.Append(At(RowCount - 1, ColumnCount - 1).ToString(format, provider).PadLeft(padding));
} }
} }
stringBuilder.Append(Environment.NewLine);
} }
return stringBuilder.ToString(); return stringBuilder.ToString();

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

@ -30,14 +30,14 @@
namespace MathNet.Numerics.LinearAlgebra.Generic namespace MathNet.Numerics.LinearAlgebra.Generic
{ {
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime;
using Factorization; using Factorization;
using Numerics; using Numerics;
using Properties; using Properties;
using Storage; using Storage;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime;
/// <summary> /// <summary>
/// Defines the base class for <c>Matrix</c> classes. /// Defines the base class for <c>Matrix</c> classes.

19
src/Numerics/LinearAlgebra/Generic/Vector.BCL.cs

@ -250,7 +250,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this vector, row by row. /// Returns a <see cref="System.String"/> that represents the content of this vector, row by row.
/// </summary> /// </summary>
public string ToVectorString(int maxLines, int maxPerLine, IFormatProvider provider) public string ToVectorString(int maxLines, int maxPerLine, IFormatProvider provider = null)
{ {
return ToVectorString(maxLines, maxPerLine, 12, "G6", provider); return ToVectorString(maxLines, maxPerLine, 12, "G6", provider);
} }
@ -258,7 +258,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary> /// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this vector, row by row. /// Returns a <see cref="System.String"/> that represents the content of this vector, row by row.
/// </summary> /// </summary>
public string ToVectorString(int maxLines, int maxPerLine, int padding, string format, IFormatProvider provider) public string ToVectorString(int maxLines, int maxPerLine, int padding, string format = null, IFormatProvider provider = null)
{ {
int fullLines = Count/maxPerLine; int fullLines = Count/maxPerLine;
int lastLine = Count%maxPerLine; int lastLine = Count%maxPerLine;
@ -274,11 +274,20 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
const string separator = " "; const string separator = " ";
string pdots = "...".PadLeft(padding); string pdots = "...".PadLeft(padding);
if (format == null)
{
format = "G8";
}
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
var iterator = GetEnumerator(); var iterator = GetEnumerator();
for (var line = 0; line < fullLines; line++) for (var line = 0; line < fullLines; line++)
{ {
if (line > 0)
{
stringBuilder.Append(Environment.NewLine);
}
iterator.MoveNext(); iterator.MoveNext();
stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding)); stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding));
for (var column = 1; column < maxPerLine; column++) for (var column = 1; column < maxPerLine; column++)
@ -287,11 +296,14 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
iterator.MoveNext(); iterator.MoveNext();
stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding)); stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding));
} }
stringBuilder.Append(Environment.NewLine);
} }
if (lastLine > 0) if (lastLine > 0)
{ {
if (fullLines > 0)
{
stringBuilder.Append(Environment.NewLine);
}
iterator.MoveNext(); iterator.MoveNext();
stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding)); stringBuilder.Append(iterator.Current.ToString(format, provider).PadLeft(padding));
for (var column = 1; column < lastLine; column++) for (var column = 1; column < lastLine; column++)
@ -305,7 +317,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
stringBuilder.Append(separator); stringBuilder.Append(separator);
stringBuilder.Append(pdots); stringBuilder.Append(pdots);
} }
stringBuilder.Append(Environment.NewLine);
} }
return stringBuilder.ToString(); return stringBuilder.ToString();

36
src/Numerics/LinearAlgebra/Single/DenseVector.cs

@ -32,10 +32,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{ {
using Distributions; using Distributions;
using Generic; using Generic;
using NumberTheory;
using Storage; using Storage;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -842,38 +840,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new float[(tokens.Count + 1) >> 1]; var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = tokens.Select(t => Single.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
{ if (data.Length == 0) throw new FormatException();
if (token == null || token.Value == textInfo.ListSeparator)
{
throw new FormatException();
}
data[i] = float.Parse(token.Value, NumberStyles.Any, formatProvider);
token = token.Next;
if (token != null)
{
token = token.Next;
}
}
return new DenseVector(data); return new DenseVector(data);
} }

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

@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Threading;
/// <summary> /// <summary>
/// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format. /// A Matrix class with sparse storage. The underlying storage scheme is 3-array compressed-sparse-row (CSR) Format.

41
src/Numerics/LinearAlgebra/Single/SparseVector.cs

@ -30,15 +30,14 @@
namespace MathNet.Numerics.LinearAlgebra.Single namespace MathNet.Numerics.LinearAlgebra.Single
{ {
using Generic;
using Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using Generic;
using NumberTheory;
using Storage;
using Threading; using Threading;
using System.Diagnostics;
/// <summary> /// <summary>
/// A vector with sparse storage. /// A vector with sparse storage.
@ -978,38 +977,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
value = value.Substring(1, value.Length - 2).Trim(); value = value.Substring(1, value.Length - 2).Trim();
} }
// keywords
var textInfo = formatProvider.GetTextInfo();
var keywords = new[] { textInfo.ListSeparator };
// lexing
var tokens = new LinkedList<string>();
GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0);
var token = tokens.First;
if (token == null || tokens.Count.IsEven())
{
throw new FormatException();
}
// parsing // parsing
var data = new float[(tokens.Count + 1) >> 1]; var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < data.Length; i++) var data = tokens.Select(t => Single.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
{ if (data.Length == 0) throw new FormatException();
if (token == null || token.Value == textInfo.ListSeparator)
{
throw new FormatException();
}
data[i] = float.Parse(token.Value, NumberStyles.Any, formatProvider);
token = token.Next;
if (token != null)
{
token = token.Next;
}
}
return new SparseVector(data); return new SparseVector(data);
} }

1
src/Numerics/Statistics/Statistics.cs

@ -301,7 +301,6 @@ namespace MathNet.Numerics.Statistics
/// Approximately median-unbiased regardless of the sample distribution (R8). /// Approximately median-unbiased regardless of the sample distribution (R8).
/// </summary> /// </summary>
/// <param name="data">The data sample sequence.</param> /// <param name="data">The data sample sequence.</param>
/// <param name="tau">Quantile selector, between 0.0 and 1.0 (inclusive).</param>
public static Func<double, double> QuantileFunc(this IEnumerable<double?> data) public static Func<double, double> QuantileFunc(this IEnumerable<double?> data)
{ {
if (data == null) throw new ArgumentNullException("data"); if (data == null) throw new ArgumentNullException("data");

41
src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using System;
using System.Globalization;
using LinearAlgebra.Complex; using LinearAlgebra.Complex;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Dense vector text handling tests. /// Dense vector text handling tests.
@ -44,20 +48,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "(2, 0)")] [TestCase("2", "(2, 0)")]
[TestCase("(3)", "(3, 0)")] [TestCase("(3)", "(3, 0)")]
[TestCase("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] [TestCase("[1,2,3]", "(1, 0) (2, 0) (3, 0)")]
[TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] [TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0) (3.4, 0) (5.6, 0)")]
[TestCase("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] [TestCase("[1+1i,2+1i,3+1i]", "(1, 1) (2, 1) (3, 1)")]
[TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] [TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1) (2.1, 1) (3.1, 1)")]
[TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] [TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1) (2.1, -1) (3.1, 1)")]
[TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")] [TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3) (3.4, 4.5) (5.6, 6.7)")]
public void CanParseComplexDenseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseComplexDenseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -66,17 +70,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] [TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "en-US")]
[TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] [TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "de-CH")]
#if !PORTABLE #if !PORTABLE
[TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] [TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1) (3,4, 1) (5,6, 1)", "de-DE")]
#endif #endif
public void CanParseComplexDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseComplexDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -96,11 +100,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

41
src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using System;
using System.Globalization;
using LinearAlgebra.Complex; using LinearAlgebra.Complex;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Sparse vector text handling tests. /// Sparse vector text handling tests.
@ -43,20 +47,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "(2, 0)")] [TestCase("2", "(2, 0)")]
[TestCase("(3)", "(3, 0)")] [TestCase("(3)", "(3, 0)")]
[TestCase("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] [TestCase("[1,2,3]", "(1, 0) (2, 0) (3, 0)")]
[TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] [TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0) (3.4, 0) (5.6, 0)")]
[TestCase("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] [TestCase("[1+1i,2+1i,3+1i]", "(1, 1) (2, 1) (3, 1)")]
[TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] [TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1) (2.1, 1) (3.1, 1)")]
[TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] [TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1) (2.1, -1) (3.1, 1)")]
[TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")] [TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3) (3.4, 4.5) (5.6, 6.7)")]
public void CanParseComplexSparseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseComplexSparseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -65,17 +69,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] [TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "en-US")]
[TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] [TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "de-CH")]
#if !PORTABLE #if !PORTABLE
[TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] [TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1) (3,4, 1) (5,6, 1)", "de-DE")]
#endif #endif
public void CanParseComplexSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseComplexSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -95,11 +99,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,16 +30,15 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{ {
using Distributions;
using LinearAlgebra.Complex;
using LinearAlgebra.Generic;
using NUnit.Framework;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Distributions;
using LinearAlgebra.Complex;
using LinearAlgebra.Generic;
using NUnit.Framework;
/// <summary> /// <summary>
/// Abstract class with the common set of vector tests. /// Abstract class with the common set of vector tests.
@ -84,9 +87,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
public void CanConvertVectorToString() public void CanConvertVectorToString()
{ {
var vector = CreateVector(Data); var vector = CreateVector(Data);
var str = vector.ToString(); var str = vector.ToVectorString(1, int.MaxValue, 1);
var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; Assert.AreEqual("(1, 1) (2, 1) (3, 1) (4, 1) (5, 1)", str);
Assert.AreEqual(string.Format("(1{0} 1){1}(2{0} 1){1}(3{0} 1){1}(4{0} 1){1}(5{0} 1)", ",", sep), str);
} }
/// <summary> /// <summary>

41
src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using System;
using System.Globalization;
using LinearAlgebra.Complex32; using LinearAlgebra.Complex32;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Dense vector text handling tests. /// Dense vector text handling tests.
@ -44,20 +48,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "(2, 0)")] [TestCase("2", "(2, 0)")]
[TestCase("(3)", "(3, 0)")] [TestCase("(3)", "(3, 0)")]
[TestCase("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] [TestCase("[1,2,3]", "(1, 0) (2, 0) (3, 0)")]
[TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] [TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0) (3.4, 0) (5.6, 0)")]
[TestCase("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] [TestCase("[1+1i,2+1i,3+1i]", "(1, 1) (2, 1) (3, 1)")]
[TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] [TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1) (2.1, 1) (3.1, 1)")]
[TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] [TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1) (2.1, -1) (3.1, 1)")]
[TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")] [TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3) (3.4, 4.5) (5.6, 6.7)")]
public void CanParseComplex32DenseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseComplex32DenseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -66,17 +70,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] [TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "en-US")]
[TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] [TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "de-CH")]
#if !PORTABLE #if !PORTABLE
[TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] [TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1) (3,4, 1) (5,6, 1)", "de-DE")]
#endif #endif
public void CanParseComplex32DenseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseComplex32DenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -96,11 +100,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

41
src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using System;
using System.Globalization;
using LinearAlgebra.Complex32; using LinearAlgebra.Complex32;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Sparse vector text handling tests. /// Sparse vector text handling tests.
@ -43,20 +47,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "(2, 0)")] [TestCase("2", "(2, 0)")]
[TestCase("(3)", "(3, 0)")] [TestCase("(3)", "(3, 0)")]
[TestCase("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] [TestCase("[1,2,3]", "(1, 0) (2, 0) (3, 0)")]
[TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] [TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0) (2.1, 0) (3.1, 0)")]
[TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] [TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0) (3.4, 0) (5.6, 0)")]
[TestCase("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] [TestCase("[1+1i,2+1i,3+1i]", "(1, 1) (2, 1) (3, 1)")]
[TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] [TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1) (2.1, 1) (3.1, 1)")]
[TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] [TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1) (2.1, -1) (3.1, 1)")]
[TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")] [TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3) (3.4, 4.5) (5.6, 6.7)")]
public void CanParseComplex32SparseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseComplex32SparseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -65,17 +69,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] [TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "en-US")]
[TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] [TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1) (3.4, 1) (5.6, 1)", "de-CH")]
#if !PORTABLE #if !PORTABLE
[TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] [TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1) (3,4, 1) (5,6, 1)", "de-DE")]
#endif #endif
public void CanParseComplex32SparseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseComplex32SparseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -95,11 +99,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,15 +30,14 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
{ {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Distributions; using Distributions;
using LinearAlgebra.Complex32; using LinearAlgebra.Complex32;
using LinearAlgebra.Generic; using LinearAlgebra.Generic;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Complex32 = Numerics.Complex32; using Complex32 = Numerics.Complex32;
/// <summary> /// <summary>
@ -84,9 +87,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void CanConvertVectorToString() public void CanConvertVectorToString()
{ {
var vector = CreateVector(Data); var vector = CreateVector(Data);
var str = vector.ToString(); var str = vector.ToVectorString(1, int.MaxValue, 1);
var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; Assert.AreEqual("(1, 1) (2, 1) (3, 1) (4, 1) (5, 1)", str);
Assert.AreEqual(string.Format("(1{0} 1){1}(2{0} 1){1}(3{0} 1){1}(4{0} 1){1}(5{0} 1)", ",", sep), str);
} }
/// <summary> /// <summary>

4
src/UnitTests/LinearAlgebraTests/Double/DenseMatrixTests.cs

@ -26,10 +26,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using System;
using System.Collections.Generic;
using LinearAlgebra.Double; using LinearAlgebra.Double;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Dense matrix tests. /// Dense matrix tests.

40
src/UnitTests/LinearAlgebraTests/Double/DenseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using System;
using System.Globalization;
using LinearAlgebra.Double; using LinearAlgebra.Double;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Dense vector text handling tests. /// Dense vector text handling tests.
@ -44,16 +48,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "2")] [TestCase("2", "2")]
[TestCase("(3)", "3")] [TestCase("(3)", "3")]
[TestCase("[1,2,3]", "1,2,3")] [TestCase("[1,2,3]", "1 2 3")]
[TestCase(" [ 1 , 2 , 3 ] ", "1,2,3")] [TestCase(" [ 1 , 2 , 3 ] ", "1 2 3")]
[TestCase(" [ -1 , 2 , +3 ] ", "-1,2,3")] [TestCase(" [ -1 , 2 , +3 ] ", "-1 2 3")]
[TestCase(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] [TestCase(" [1.2,3.4 , 5.6] ", "1.2 3.4 5.6")]
public void CanParseDoubleDenseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseDoubleDenseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -62,15 +66,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2,3.4 , 5.6 ", "1.2,3.4,5.6", "en-US")] [TestCase(" 1.2,3.4 , 5.6 ", "1.2 3.4 5.6", "en-US")]
[TestCase(" 1.2;3.4 ; 5.6 ", "1.2;3.4;5.6", "de-CH")] [TestCase(" 1.2;3.4 ; 5.6 ", "1.2 3.4 5.6", "de-CH")]
[TestCase(" 1,2;3,4 ; 5,6 ", "1,2;3,4;5,6", "de-DE")] [TestCase(" 1,2;3,4 ; 5,6 ", "1,2 3,4 5,6", "de-DE")]
public void CanParseDoubleDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseDoubleDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -78,17 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="vectorAsString">Vector as string.</param> /// <param name="vectorAsString">Vector as string.</param>
[TestCase("15")] [TestCase("15")]
[TestCase("1{0}2{1}3{0}4{1}5{0}6")] [TestCase("1{0}2 3{0}4 5{0}6")]
public void CanParseDoubleDenseVectors(string vectorAsString) public void CanParseDoubleDenseVectors(string vectorAsString)
{ {
var mappedString = String.Format( var mappedString = String.Format(
vectorAsString, vectorAsString,
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
CultureInfo.CurrentCulture.TextInfo.ListSeparator);
var vector = DenseVector.Parse(mappedString); var vector = DenseVector.Parse(mappedString);
Assert.AreEqual(mappedString, vector.ToString()); Assert.AreEqual(mappedString, vector.ToVectorString(1, int.MaxValue, 1));
} }
/// <summary> /// <summary>
@ -132,11 +135,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

40
src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using System;
using System.Globalization;
using LinearAlgebra.Double; using LinearAlgebra.Double;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Sparse vector text handling tests. /// Sparse vector text handling tests.
@ -43,16 +47,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "2")] [TestCase("2", "2")]
[TestCase("(3)", "3")] [TestCase("(3)", "3")]
[TestCase("[1,2,3]", "1,2,3")] [TestCase("[1,2,3]", "1 2 3")]
[TestCase(" [ 1 , 2 , 3 ] ", "1,2,3")] [TestCase(" [ 1 , 2 , 3 ] ", "1 2 3")]
[TestCase(" [ -1 , 2 , +3 ] ", "-1,2,3")] [TestCase(" [ -1 , 2 , +3 ] ", "-1 2 3")]
[TestCase(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] [TestCase(" [1.2,3.4 , 5.6] ", "1.2 3.4 5.6")]
public void CanParseDoubleSparseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseDoubleSparseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -61,15 +65,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2,3.4 , 5.6 ", "1.2,3.4,5.6", "en-US")] [TestCase(" 1.2,3.4 , 5.6 ", "1.2 3.4 5.6", "en-US")]
[TestCase(" 1.2;3.4 ; 5.6 ", "1.2;3.4;5.6", "de-CH")] [TestCase(" 1.2;3.4 ; 5.6 ", "1.2 3.4 5.6", "de-CH")]
[TestCase(" 1,2;3,4 ; 5,6 ", "1,2;3,4;5,6", "de-DE")] [TestCase(" 1,2;3,4 ; 5,6 ", "1,2 3,4 5,6", "de-DE")]
public void CanParseDoubleSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseDoubleSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -77,17 +81,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
/// </summary> /// </summary>
/// <param name="vectorAsString">Vector as string.</param> /// <param name="vectorAsString">Vector as string.</param>
[TestCase("15")] [TestCase("15")]
[TestCase("1{0}2{1}3{0}4{1}5{0}6")] [TestCase("1{0}2 3{0}4 5{0}6")]
public void CanParseDoubleSparseVectors(string vectorAsString) public void CanParseDoubleSparseVectors(string vectorAsString)
{ {
var mappedString = String.Format( var mappedString = String.Format(
vectorAsString, vectorAsString,
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
CultureInfo.CurrentCulture.TextInfo.ListSeparator);
var vector = SparseVector.Parse(mappedString); var vector = SparseVector.Parse(mappedString);
Assert.AreEqual(mappedString, vector.ToString()); Assert.AreEqual(mappedString, vector.ToVectorString(1, int.MaxValue, 1));
} }
/// <summary> /// <summary>
@ -131,11 +134,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,14 +30,13 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
{ {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Distributions; using Distributions;
using LinearAlgebra.Double; using LinearAlgebra.Double;
using LinearAlgebra.Generic; using LinearAlgebra.Generic;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Abstract class with the common set of vector tests. /// Abstract class with the common set of vector tests.
@ -82,9 +85,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
public void CanConvertVectorToString() public void CanConvertVectorToString()
{ {
var vector = CreateVector(Data); var vector = CreateVector(Data);
var str = vector.ToString(); var str = vector.ToVectorString(1, int.MaxValue, 1);
var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; Assert.AreEqual("1 2 3 4 5", str);
Assert.AreEqual(string.Format("1{0}2{0}3{0}4{0}5", sep), str);
} }
/// <summary> /// <summary>

40
src/UnitTests/LinearAlgebraTests/Single/DenseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using System;
using System.Globalization;
using LinearAlgebra.Single; using LinearAlgebra.Single;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Dense vector text handling tests. /// Dense vector text handling tests.
@ -44,16 +48,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "2")] [TestCase("2", "2")]
[TestCase("(3)", "3")] [TestCase("(3)", "3")]
[TestCase("[1,2,3]", "1,2,3")] [TestCase("[1,2,3]", "1 2 3")]
[TestCase(" [ 1 , 2 , 3 ] ", "1,2,3")] [TestCase(" [ 1 , 2 , 3 ] ", "1 2 3")]
[TestCase(" [ -1 , 2 , +3 ] ", "-1,2,3")] [TestCase(" [ -1 , 2 , +3 ] ", "-1 2 3")]
[TestCase(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] [TestCase(" [1.2,3.4 , 5.6] ", "1.2 3.4 5.6")]
public void CanParseSingleDenseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseSingleDenseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -62,15 +66,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2,3.4 , 5.6 ", "1.2,3.4,5.6", "en-US")] [TestCase(" 1.2,3.4 , 5.6 ", "1.2 3.4 5.6", "en-US")]
[TestCase(" 1.2;3.4 ; 5.6 ", "1.2;3.4;5.6", "de-CH")] [TestCase(" 1.2;3.4 ; 5.6 ", "1.2 3.4 5.6", "de-CH")]
[TestCase(" 1,2;3,4 ; 5,6 ", "1,2;3,4;5,6", "de-DE")] [TestCase(" 1,2;3,4 ; 5,6 ", "1,2 3,4 5,6", "de-DE")]
public void CanParseSingleDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseSingleDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = DenseVector.Parse(stringToParse, formatProvider); var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -78,17 +82,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="vectorAsString">Vector as string.</param> /// <param name="vectorAsString">Vector as string.</param>
[TestCase("15")] [TestCase("15")]
[TestCase("1{0}2{1}3{0}4{1}5{0}6")] [TestCase("1{0}2 3{0}4 5{0}6")]
public void CanParseSingleDenseVectors(string vectorAsString) public void CanParseSingleDenseVectors(string vectorAsString)
{ {
var mappedString = String.Format( var mappedString = String.Format(
vectorAsString, vectorAsString,
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
CultureInfo.CurrentCulture.TextInfo.ListSeparator);
var vector = DenseVector.Parse(mappedString); var vector = DenseVector.Parse(mappedString);
Assert.AreEqual(mappedString, vector.ToString()); Assert.AreEqual(mappedString, vector.ToVectorString(1, int.MaxValue, 1, "G"));
} }
/// <summary> /// <summary>
@ -132,11 +135,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

40
src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.TextHandling.cs

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,10 +30,10 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using System;
using System.Globalization;
using LinearAlgebra.Single; using LinearAlgebra.Single;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Globalization;
/// <summary> /// <summary>
/// Sparse vector text handling tests. /// Sparse vector text handling tests.
@ -43,16 +47,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
[TestCase("2", "2")] [TestCase("2", "2")]
[TestCase("(3)", "3")] [TestCase("(3)", "3")]
[TestCase("[1,2,3]", "1,2,3")] [TestCase("[1,2,3]", "1 2 3")]
[TestCase(" [ 1 , 2 , 3 ] ", "1,2,3")] [TestCase(" [ 1 , 2 , 3 ] ", "1 2 3")]
[TestCase(" [ -1 , 2 , +3 ] ", "-1,2,3")] [TestCase(" [ -1 , 2 , +3 ] ", "-1 2 3")]
[TestCase(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] [TestCase(" [1.2,3.4 , 5.6] ", "1.2 3.4 5.6")]
public void CanParseSingleSparseVectorsWithInvariant(string stringToParse, string expectedToString) public void CanParseSingleSparseVectorsWithInvariant(string stringToParse, string expectedToString)
{ {
var formatProvider = CultureInfo.InvariantCulture; var formatProvider = CultureInfo.InvariantCulture;
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -61,15 +65,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// <param name="stringToParse">String to parse.</param> /// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param> /// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param> /// <param name="culture">Culture name.</param>
[TestCase(" 1.2,3.4 , 5.6 ", "1.2,3.4,5.6", "en-US")] [TestCase(" 1.2,3.4 , 5.6 ", "1.2 3.4 5.6", "en-US")]
[TestCase(" 1.2;3.4 ; 5.6 ", "1.2;3.4;5.6", "de-CH")] [TestCase(" 1.2;3.4 ; 5.6 ", "1.2 3.4 5.6", "de-CH")]
[TestCase(" 1,2;3,4 ; 5,6 ", "1,2;3,4;5,6", "de-DE")] [TestCase(" 1,2;3,4 ; 5,6 ", "1,2 3,4 5,6", "de-DE")]
public void CanParseSingleSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture) public void CanParseSingleSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{ {
var formatProvider = new CultureInfo(culture); var formatProvider = new CultureInfo(culture);
var vector = SparseVector.Parse(stringToParse, formatProvider); var vector = SparseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider)); Assert.AreEqual(expectedToString, vector.ToVectorString(1, int.MaxValue, 1, "G", formatProvider));
} }
/// <summary> /// <summary>
@ -77,17 +81,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
/// </summary> /// </summary>
/// <param name="vectorAsString">Vector as string.</param> /// <param name="vectorAsString">Vector as string.</param>
[TestCase("15")] [TestCase("15")]
[TestCase("1{0}2{1}3{0}4{1}5{0}6")] [TestCase("1{0}2 3{0}4 5{0}6")]
public void CanParseSingleSparseVectors(string vectorAsString) public void CanParseSingleSparseVectors(string vectorAsString)
{ {
var mappedString = String.Format( var mappedString = String.Format(
vectorAsString, vectorAsString,
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
CultureInfo.CurrentCulture.TextInfo.ListSeparator);
var vector = SparseVector.Parse(mappedString); var vector = SparseVector.Parse(mappedString);
Assert.AreEqual(mappedString, vector.ToString()); Assert.AreEqual(mappedString, vector.ToVectorString(1, int.MaxValue, 1, "G"));
} }
/// <summary> /// <summary>
@ -131,11 +134,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
[TestCase(null)] [TestCase(null)]
[TestCase("")] [TestCase("")]
[TestCase(",")] [TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")] [TestCase("1e+")]
[TestCase("1e")] [TestCase("1e")]
[TestCase("()")] [TestCase("()")]

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

@ -3,7 +3,9 @@
// http://numerics.mathdotnet.com // http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics // http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com // http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET //
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person // Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation // obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without // files (the "Software"), to deal in the Software without
@ -12,8 +14,10 @@
// copies of the Software, and to permit persons to whom the // copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following // Software is furnished to do so, subject to the following
// conditions: // conditions:
//
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -26,14 +30,13 @@
namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
{ {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Distributions; using Distributions;
using LinearAlgebra.Generic; using LinearAlgebra.Generic;
using LinearAlgebra.Single; using LinearAlgebra.Single;
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary> /// <summary>
/// Abstract class with the common set of vector tests. /// Abstract class with the common set of vector tests.
@ -73,6 +76,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
Assert.AreEqual(vector.Count, clone.Count); Assert.AreEqual(vector.Count, clone.Count);
CollectionAssert.AreEqual(vector, clone); CollectionAssert.AreEqual(vector, clone);
} }
#endif
/// <summary> /// <summary>
/// Can convert vector to string. /// Can convert vector to string.
@ -81,11 +85,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
public void CanConvertVectorToString() public void CanConvertVectorToString()
{ {
var vector = CreateVector(Data); var vector = CreateVector(Data);
var str = vector.ToString(); var str = vector.ToVectorString(1, int.MaxValue, 1);
var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; Assert.AreEqual("1 2 3 4 5", str);
Assert.AreEqual(string.Format("1{0}2{0}3{0}4{0}5", sep), str);
} }
#endif
/// <summary> /// <summary>
/// Can copy part of a vector to another vector. /// Can copy part of a vector to another vector.

Loading…
Cancel
Save