Browse Source

LA: Adapt parsing and unit tests to modified string formatting

pull/112/head
Christoph Ruegg 13 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
{
using System;
using Algorithms.LinearAlgebra;
using System;
/// <summary>
/// Sets parameters for the library.

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

@ -28,12 +28,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Complex
{
using Distributions;
using Generic;
using NumberTheory;
using Storage;
using System;
using System.Collections.Generic;
@ -758,39 +756,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
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
var data = new Complex[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
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;
}
data[i] = token.Value.ToComplex(formatProvider);
token = token.Next;
if (token != null)
if (current != string.Empty)
{
token = token.Next;
throw new FormatException();
}
}
return new DenseVector(data);
if (data.Count == 0)
{
throw new FormatException();
}
return new DenseVector(data.ToArray());
}
/// <summary>

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

@ -37,7 +37,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Threading;
/// <summary>
/// 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
{
using Generic;
using NumberTheory;
using Storage;
using System;
using System.Collections.Generic;
@ -941,39 +940,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
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
var data = new Complex[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
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;
}
data[i] = token.Value.ToComplex(formatProvider);
token = token.Next;
if (token != null)
if (current != string.Empty)
{
token = token.Next;
throw new FormatException();
}
}
return new SparseVector(data);
if (data.Count == 0)
{
throw new FormatException();
}
return new SparseVector(data.ToArray());
}
/// <summary>

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

@ -32,7 +32,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
using Distributions;
using Generic;
using NumberTheory;
using Numerics;
using Storage;
using System;
@ -757,39 +756,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
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
var data = new Complex32[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
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;
}
data[i] = token.Value.ToComplex32(formatProvider);
token = token.Next;
if (token != null)
if (current != string.Empty)
{
token = token.Next;
throw new FormatException();
}
}
return new DenseVector(data);
if (data.Count == 0)
{
throw new FormatException();
}
return new DenseVector(data.ToArray());
}
/// <summary>

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

@ -37,7 +37,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Threading;
/// <summary>
/// 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
{
using Generic;
using NumberTheory;
using Numerics;
using Storage;
using System;
@ -941,39 +940,38 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
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
var data = new Complex32[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
var strongTokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator }, StringSplitOptions.RemoveEmptyEntries);
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;
}
data[i] = token.Value.ToComplex32(formatProvider);
token = token.Next;
if (token != null)
if (current != string.Empty)
{
token = token.Next;
throw new FormatException();
}
}
return new SparseVector(data);
if (data.Count == 0)
{
throw new FormatException();
}
return new SparseVector(data.ToArray());
}
/// <summary>

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

@ -32,11 +32,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
using Distributions;
using Generic;
using NumberTheory;
using Properties;
using Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
@ -852,38 +850,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
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
var data = new double[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
{
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;
}
}
var tokens = value.Split(new[] {formatProvider.GetTextInfo().ListSeparator, " ", "\t"}, StringSplitOptions.RemoveEmptyEntries);
var data = tokens.Select(t => Double.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
if (data.Length == 0) throw new FormatException();
return new DenseVector(data);
}

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

@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Threading;
/// <summary>
/// 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
{
using Generic;
using NumberTheory;
using Storage;
using System;
using System.Collections.Generic;
@ -974,38 +973,10 @@ namespace MathNet.Numerics.LinearAlgebra.Double
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
var data = new double[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
{
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;
}
}
var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
var data = tokens.Select(t => Double.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
if (data.Length == 0) throw new FormatException();
return new SparseVector(data);
}

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

@ -101,7 +101,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this matrix.
/// </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);
}
@ -109,7 +109,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// <summary>
/// Returns a <see cref="System.String"/> that represents the content of this matrix.
/// </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;
bool rowDots = maxRows < RowCount;
@ -123,10 +123,19 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
const string dots = "...";
string pdots = "...".PadLeft(padding);
if (format == null)
{
format = "G8";
}
var stringBuilder = new StringBuilder();
for (var row = 0; row < rowN; row++)
{
if (row > 0)
{
stringBuilder.Append(Environment.NewLine);
}
stringBuilder.Append(At(row, 0).ToString(format, provider).PadLeft(padding));
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(Environment.NewLine);
}
if (rowDots)
{
stringBuilder.Append(Environment.NewLine);
stringBuilder.Append(pdots);
for (var column = 1; column < colN; column++)
{
@ -164,11 +173,11 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
stringBuilder.Append(pdots);
}
}
stringBuilder.Append(Environment.NewLine);
}
if (rowLast)
{
stringBuilder.Append(Environment.NewLine);
stringBuilder.Append(At(RowCount - 1, 0).ToString(format, provider).PadLeft(padding));
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(Environment.NewLine);
}
return stringBuilder.ToString();

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

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

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

@ -32,10 +32,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
using Distributions;
using Generic;
using NumberTheory;
using Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
@ -842,38 +840,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
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
var data = new float[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
{
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;
}
}
var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
var data = tokens.Select(t => Single.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
if (data.Length == 0) throw new FormatException();
return new DenseVector(data);
}

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

@ -36,7 +36,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Threading;
/// <summary>
/// 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
{
using Generic;
using Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Generic;
using NumberTheory;
using Storage;
using Threading;
using System.Diagnostics;
/// <summary>
/// A vector with sparse storage.
@ -978,38 +977,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
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
var data = new float[(tokens.Count + 1) >> 1];
for (var i = 0; i < data.Length; i++)
{
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;
}
}
var tokens = value.Split(new[] { formatProvider.GetTextInfo().ListSeparator, " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
var data = tokens.Select(t => Single.Parse(t, NumberStyles.Any, formatProvider)).ToArray();
if (data.Length == 0) throw new FormatException();
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).
/// </summary>
/// <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)
{
if (data == null) throw new ArgumentNullException("data");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save