diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs index 4b2afb4c..6987c17f 100644 --- a/src/Numerics/Complex32.cs +++ b/src/Numerics/Complex32.cs @@ -682,52 +682,8 @@ namespace MathNet.Numerics /// public string ToString(string format, IFormatProvider formatProvider) { - var numberFormatInfo = formatProvider.GetNumberFormatInfo(); - - if (IsNaN()) - { - return numberFormatInfo.NaNSymbol; - } - - if (IsInfinity()) - { - return numberFormatInfo.PositiveInfinitySymbol; - } - var ret = new StringBuilder(); - - if (_real != 0.0f) - { - ret.Append(_real.ToString(format, formatProvider)); - } - - if (_imag != 0.0f) - { - if (_real != 0.0f) - { - if (_imag < 0) - { - ret.Append(" - "); - } - else - { - ret.Append(" + "); - } - - ret.Append(Math.Abs(_imag).ToString(format, formatProvider)).Append("i"); - } - else - { - ret.Append(_imag.ToString(format, formatProvider)).Append("i"); - } - - } - - if (ret.Length == 0) - { - ret.Append(0.0f.ToString(format, formatProvider)); - } - + ret.Append("(").Append(_real.ToString(format, formatProvider)).Append(", ").Append(_imag.ToString(format, formatProvider)).Append(")"); return ret.ToString(); } diff --git a/src/Numerics/LinearAlgebra/Double/IO/DelimitedWriter.cs b/src/Numerics/LinearAlgebra/IO/DelimitedWriter.cs similarity index 89% rename from src/Numerics/LinearAlgebra/Double/IO/DelimitedWriter.cs rename to src/Numerics/LinearAlgebra/IO/DelimitedWriter.cs index 858df4d8..47ea5290 100644 --- a/src/Numerics/LinearAlgebra/Double/IO/DelimitedWriter.cs +++ b/src/Numerics/LinearAlgebra/IO/DelimitedWriter.cs @@ -26,7 +26,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // -namespace MathNet.Numerics.LinearAlgebra.Double.IO +namespace MathNet.Numerics.LinearAlgebra.IO { using System; using System.Collections.Generic; @@ -35,10 +35,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO using Generic; /// - /// Writes an to delimited text file. If the user does not + /// Writes an to delimited text file. If the user does not /// specify a delimiter, a tab separator is used. /// - public class DelimitedWriter : MatrixWriter + /// The data type of the matrix. + public class DelimitedWriter : MatrixWriter where TDataType : struct, IEquatable, IFormattable { /// /// The delimiter to use. @@ -51,7 +52,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO private CultureInfo _cultureInfo = CultureInfo.CurrentCulture; /// - /// Initializes a new instance of the class using + /// Initializes a new instance of the class. /// a comma as the delimiter. /// public DelimitedWriter() @@ -60,7 +61,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class. /// using the given delimiter. /// /// @@ -72,7 +73,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class. /// using the given delimiter. /// /// @@ -116,13 +117,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given . + /// Writes the given to the given . /// /// The matrix to write. /// The to write the matrix to. /// The format to use on each element. /// If either or is null. - protected override void DoWriteMatrix(Matrix matrix, TextWriter writer, string format) + protected override void DoWriteMatrix(Matrix matrix, TextWriter writer, string format) { if (matrix == null) { diff --git a/src/Numerics/LinearAlgebra/Double/IO/MatrixWriter.cs b/src/Numerics/LinearAlgebra/IO/MatrixWriter.cs similarity index 81% rename from src/Numerics/LinearAlgebra/Double/IO/MatrixWriter.cs rename to src/Numerics/LinearAlgebra/IO/MatrixWriter.cs index 9f26c151..e955034b 100644 --- a/src/Numerics/LinearAlgebra/Double/IO/MatrixWriter.cs +++ b/src/Numerics/LinearAlgebra/IO/MatrixWriter.cs @@ -29,23 +29,24 @@ using System; using System.IO; -namespace MathNet.Numerics.LinearAlgebra.Double.IO +namespace MathNet.Numerics.LinearAlgebra.IO { using Generic; /// - /// Base class to write a single to a file or stream. + /// Base class to write a single to a file or stream. /// - public abstract class MatrixWriter + /// The data type of the matrix. + public abstract class MatrixWriter where TDataType : struct, IEquatable, IFormattable { /// - /// Writes the given to the given file. If the file already exists, + /// Writes the given to the given file. If the file already exists, /// the file will be overwritten. /// /// The matrix to write. /// The file to write the matrix to. /// If either or is null. - public void WriteMatrix(Matrix matrix, string file) + public void WriteMatrix(Matrix matrix, string file) { if (matrix == null) { @@ -64,14 +65,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given file. If the file already exists, + /// Writes the given to the given file. If the file already exists, /// the file will be overwritten. /// /// the matrix to write. /// The file to write the matrix to. /// The format to use on each element. /// If either or is null. - public void WriteMatrix(Matrix matrix, string file, string format) + public void WriteMatrix(Matrix matrix, string file, string format) { if (matrix == null) { @@ -95,12 +96,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given stream. + /// Writes the given to the given stream. /// /// The matrix to write. /// The to write the matrix to. /// If either or is null. - public void WriteMatrix(Matrix matrix, Stream stream) + public void WriteMatrix(Matrix matrix, Stream stream) { if (matrix == null) { @@ -119,13 +120,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given stream. + /// Writes the given to the given stream. /// /// The to write. /// The to write the matrix to. /// The format to use on each element. /// If either or is null. - public void WriteMatrix(Matrix matrix, Stream stream, string format) + public void WriteMatrix(Matrix matrix, Stream stream, string format) { if (matrix == null) { @@ -144,12 +145,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given . + /// Writes the given to the given . /// /// The matrix to write. /// The to write the matrix to. /// If either or is null. - public void WriteMatrix(Matrix matrix, TextWriter writer) + public void WriteMatrix(Matrix matrix, TextWriter writer) { if (matrix == null) { @@ -165,13 +166,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO } /// - /// Writes the given to the given . + /// Writes the given to the given . /// /// The matrix to write. /// The to write the matrix to. /// The format to use on each element. /// If either or is null. - public void WriteMatrix(Matrix matrix, TextWriter writer, string format) + public void WriteMatrix(Matrix matrix, TextWriter writer, string format) { if (matrix == null) { @@ -192,6 +193,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double.IO /// The matrix to serialize. /// The to write the matrix to. /// The format for the new matrix. - protected abstract void DoWriteMatrix(Matrix matrix, TextWriter writer, string format); + protected abstract void DoWriteMatrix(Matrix matrix, TextWriter writer, string format); } } diff --git a/src/Numerics/LinearAlgebra/Single/IO/DelimitedWriter.cs b/src/Numerics/LinearAlgebra/Single/IO/DelimitedWriter.cs deleted file mode 100644 index 416764c9..00000000 --- a/src/Numerics/LinearAlgebra/Single/IO/DelimitedWriter.cs +++ /dev/null @@ -1,168 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 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 -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// 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 -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -namespace MathNet.Numerics.LinearAlgebra.Single.IO -{ - using System; - using System.Collections.Generic; - using System.Globalization; - using System.IO; - using Generic; - - /// - /// Writes an to delimited text file. If the user does not - /// specify a delimiter, a tab separator is used. - /// - public class DelimitedWriter : MatrixWriter - { - /// - /// The delimiter to use. - /// - private readonly string _delimiter; - - /// - /// The to use. - /// - private CultureInfo _cultureInfo = CultureInfo.CurrentCulture; - - /// - /// Initializes a new instance of the class using - /// a comma as the delimiter. - /// - public DelimitedWriter() - { - _delimiter = ","; - } - - /// - /// Initializes a new instance of the class - /// using the given delimiter. - /// - /// - /// the delimiter to use. - /// - public DelimitedWriter(char delimiter) - { - _delimiter = new string(delimiter, 1); - } - - /// - /// Initializes a new instance of the class - /// using the given delimiter. - /// - /// - /// the delimiter to use. - /// - public DelimitedWriter(string delimiter) - { - _delimiter = delimiter; - } - - /// - /// Gets or sets the column header values. - /// - /// The column header values. - /// Will write the column headers if the list is not empty or null. - public IList ColumnHeaders - { - get; - set; - } - - /// - /// Gets or sets the to use when parsing the numbers. - /// - /// The culture info. - /// Defaults to CultureInfo.CurrentCulture. - public CultureInfo CultureInfo - { - get - { - return _cultureInfo; - } - - set - { - if (value != null) - { - _cultureInfo = value; - } - } - } - - /// - /// Writes the given to the given . - /// - /// The matrix to write. - /// The to write the matrix to. - /// The format to use on each element. - /// If either or is null. - protected override void DoWriteMatrix(Matrix matrix, TextWriter writer, string format) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (writer == null) - { - throw new ArgumentNullException("writer"); - } - - if (ColumnHeaders != null && ColumnHeaders.Count > 0) - { - for (var i = 0; i < ColumnHeaders.Count - 1; i++) - { - writer.Write(ColumnHeaders[i]); - writer.Write(_delimiter); - } - - writer.WriteLine(ColumnHeaders[ColumnHeaders.Count - 1]); - } - - var cols = matrix.ColumnCount - 1; - var rows = matrix.RowCount - 1; - for (var i = 0; i < matrix.RowCount; i++) - { - for (var j = 0; j < matrix.ColumnCount; j++) - { - writer.Write(matrix[i, j].ToString(format, _cultureInfo)); - if (j != cols) - { - writer.Write(_delimiter); - } - } - - if (i != rows) - { - writer.Write(Environment.NewLine); - } - } - } - } -} diff --git a/src/Numerics/LinearAlgebra/Single/IO/MatrixWriter.cs b/src/Numerics/LinearAlgebra/Single/IO/MatrixWriter.cs deleted file mode 100644 index d1d9a2d3..00000000 --- a/src/Numerics/LinearAlgebra/Single/IO/MatrixWriter.cs +++ /dev/null @@ -1,197 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://numerics.mathdotnet.com -// http://github.com/mathnet/mathnet-numerics -// http://mathnetnumerics.codeplex.com -// -// Copyright (c) 2009-2010 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 -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// 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 -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; - -namespace MathNet.Numerics.LinearAlgebra.Single.IO -{ - using Generic; - - /// - /// Base class to write a single to a file or stream. - /// - public abstract class MatrixWriter - { - /// - /// Writes the given to the given file. If the file already exists, - /// the file will be overwritten. - /// - /// The matrix to write. - /// The file to write the matrix to. - /// If either or is null. - public void WriteMatrix(Matrix matrix, string file) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (file == null) - { - throw new ArgumentNullException("file"); - } - - using (var writer = new StreamWriter(file)) - { - DoWriteMatrix(matrix, writer, null); - } - } - - /// - /// Writes the given to the given file. If the file already exists, - /// the file will be overwritten. - /// - /// the matrix to write. - /// The file to write the matrix to. - /// The format to use on each element. - /// If either or is null. - public void WriteMatrix(Matrix matrix, string file, string format) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (file == null) - { - throw new ArgumentNullException("file"); - } - - if (File.Exists(file)) - { - File.Delete(file); - } - - using (var writer = new StreamWriter(file)) - { - DoWriteMatrix(matrix, writer, format); - } - } - - /// - /// Writes the given to the given stream. - /// - /// The matrix to write. - /// The to write the matrix to. - /// If either or is null. - public void WriteMatrix(Matrix matrix, Stream stream) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - using (var writer = new StreamWriter(stream)) - { - DoWriteMatrix(matrix, writer, null); - } - } - - /// - /// Writes the given to the given stream. - /// - /// The to write. - /// The to write the matrix to. - /// The format to use on each element. - /// If either or is null. - public void WriteMatrix(Matrix matrix, Stream stream, string format) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (stream == null) - { - throw new ArgumentNullException("stream"); - } - - using (var writer = new StreamWriter(stream)) - { - DoWriteMatrix(matrix, writer, format); - } - } - - /// - /// Writes the given to the given . - /// - /// The matrix to write. - /// The to write the matrix to. - /// If either or is null. - public void WriteMatrix(Matrix matrix, TextWriter writer) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (writer == null) - { - throw new ArgumentNullException("writer"); - } - - DoWriteMatrix(matrix, writer, null); - } - - /// - /// Writes the given to the given . - /// - /// The matrix to write. - /// The to write the matrix to. - /// The format to use on each element. - /// If either or is null. - public void WriteMatrix(Matrix matrix, TextWriter writer, string format) - { - if (matrix == null) - { - throw new ArgumentNullException("matrix"); - } - - if (writer == null) - { - throw new ArgumentNullException("writer"); - } - - DoWriteMatrix(matrix, writer, format); - } - - /// - /// Subclasses must implement this method to do the actually writing. - /// - /// The matrix to serialize. - /// The to write the matrix to. - /// The format for the new matrix. - protected abstract void DoWriteMatrix(Matrix matrix, TextWriter writer, string format); - } -} diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index a2f4349a..2817748f 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -199,6 +199,8 @@ + + @@ -215,12 +217,10 @@ - - @@ -257,12 +257,10 @@ - - diff --git a/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs b/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs index 82b30714..8d769e2d 100644 --- a/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs +++ b/src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs @@ -38,22 +38,21 @@ namespace MathNet.Numerics.UnitTests.ComplexTests public class Complex32TextHandlingTest { [Test] - [Row(1, -2, "1 - 2i")] - [Row(1, 2, "1 + 2i")] - [Row(1, 0, "1")] - [Row(0, -2, "-2i")] - [Row(0, 2, "2i")] - [Row(0, 2, "2i")] - [Row(0, 0, "0")] - [Row(Double.NaN, Double.NaN, "{1}")] - [Row(Double.NaN, 0, "{1}")] - [Row(0, Double.NaN, "{1}")] - [Row(Double.PositiveInfinity, Double.PositiveInfinity, "{2}")] - [Row(1.1, 0, "1{0}1")] - [Row(-1.1, 0, "-1{0}1")] - [Row(0, 1.1, "1{0}1i")] - [Row(0, -1.1, "-1{0}1i")] - [Row(1.1, 1.1, "1{0}1 + 1{0}1i")] + [Row(1, -2, "(1, -2)")] + [Row(1, 2, "(1, 2)")] + [Row(1, 0, "(1, 0)")] + [Row(0, -2, "(0, -2)")] + [Row(0, 2, "(0, 2)")] + [Row(0, 0, "(0, 0)")] + [Row(Double.NaN, Double.NaN, "({1}, {1})")] + [Row(Double.NaN, 0, "({1}, 0)")] + [Row(0, Double.NaN, "(0, {1})")] + [Row(Double.PositiveInfinity, Double.PositiveInfinity, "({2}, {2})")] + [Row(1.1, 0, "(1{0}1, 0)")] + [Row(-1.1, 0, "(-1{0}1, 0)")] + [Row(0, 1.1, "(0, 1{0}1)")] + [Row(0, -1.1, "(0, -1{0}1)")] + [Row(1.1, 1.1, "(1{0}1, 1{0}1)")] public void CanFormatComplexToString(float real, float imag, string expected) { var numberFormat = NumberFormatInfo.CurrentInfo; @@ -78,31 +77,31 @@ namespace MathNet.Numerics.UnitTests.ComplexTests string cultureName, string nan, string infinity, string number) { var provider = CultureInfo.GetCultureInfo(cultureName); - Assert.AreEqual(nan, Complex32.NaN.ToString(provider)); - Assert.AreEqual(infinity, Complex32.Infinity.ToString(provider)); - Assert.AreEqual("0", Complex32.Zero.ToString(provider)); - Assert.AreEqual(String.Format("{0}", number), new Complex32(1.1f, 0.0f).ToString(provider)); - Assert.AreEqual(String.Format("-{0}", number), new Complex32(-1.1f, 0f).ToString(provider)); - Assert.AreEqual(String.Format("-{0}i", number), new Complex32(0.0f, -1.1f).ToString(provider)); - Assert.AreEqual(String.Format("{0}i", number), new Complex32(0.0f, 1.1f).ToString(provider)); - Assert.AreEqual(String.Format("{0} + {0}i", number), new Complex32(1.1f, 1.1f).ToString(provider)); + Assert.AreEqual("(" + nan + ", " + nan + ")", Complex32.NaN.ToString(provider)); + Assert.AreEqual("(" + infinity + ", " + infinity + ")", Complex32.Infinity.ToString(provider)); + Assert.AreEqual("(0, 0)", Complex32.Zero.ToString(provider)); + Assert.AreEqual("(" + String.Format("{0}", number) + ", 0)", new Complex32(1.1f, 0.0f).ToString(provider)); + Assert.AreEqual("(" + String.Format("-{0}", number) + ", 0)", new Complex32(-1.1f, 0f).ToString(provider)); + Assert.AreEqual("(0, " + String.Format("-{0}", number) + ")", new Complex32(0.0f, -1.1f).ToString(provider)); + Assert.AreEqual("(0, " + String.Format("{0}", number) + ")", new Complex32(0.0f, 1.1f).ToString(provider)); + Assert.AreEqual("(" + String.Format("{0}", number) + ", " + String.Format("{0}", number) + ")", new Complex32(1.1f, 1.1f).ToString(provider)); } [Test] [MultipleAsserts] public void CanFormatComplexToStringWithFormat() { - Assert.AreEqual("0", String.Format("{0:G}", Complex32.Zero)); - Assert.AreEqual("1 + 2i", String.Format("{0:G}", new Complex32(1, 2))); - Assert.AreEqual("001 + 002i", String.Format("{0:000;minus 000;zero}", new Complex32(1, 2))); - Assert.AreEqual("minus 002i", String.Format("{0:000;minus 000;zero}", new Complex32(0, -2))); - Assert.AreEqual("zero", String.Format("{0:000;minus 000;zero}", Complex32.Zero)); + Assert.AreEqual("(0, 0)", String.Format("{0:G}", Complex32.Zero)); + Assert.AreEqual("(1, 2)", String.Format("{0:G}", new Complex32(1, 2))); + Assert.AreEqual("(001, 002)", String.Format("{0:000;minus 000;zero}", new Complex32(1, 2))); + Assert.AreEqual("(zero, minus 002)", String.Format("{0:000;minus 000;zero}", new Complex32(0, -2))); + Assert.AreEqual("(zero, zero)", String.Format("{0:000;minus 000;zero}", Complex32.Zero)); - Assert.AreEqual("0", Complex32.Zero.ToString("G")); - Assert.AreEqual("1 + 2i", new Complex32(1, 2).ToString("G")); - Assert.AreEqual("001 + 002i", new Complex32(1, 2).ToString("#000;minus 000;zero")); - Assert.AreEqual("minus 002i", new Complex32(0, -2).ToString("#000;minus 000;zero")); - Assert.AreEqual("zero", Complex32.Zero.ToString("#000;minus 000;zero")); + Assert.AreEqual("(0, 0)", Complex32.Zero.ToString("G")); + Assert.AreEqual("(1, 2)", new Complex32(1, 2).ToString("G")); + Assert.AreEqual("(001, 002)", new Complex32(1, 2).ToString("#000;minus 000;zero")); + Assert.AreEqual("(zero, minus 002)", new Complex32(0, -2).ToString("#000;minus 000;zero")); + Assert.AreEqual("(zero, zero)", Complex32.Zero.ToString("#000;minus 000;zero")); } [Test] @@ -111,18 +110,18 @@ namespace MathNet.Numerics.UnitTests.ComplexTests { var culture = CultureInfo.InvariantCulture; - Assert.AreEqual("NaN", String.Format(culture, "{0:.000}", Complex32.NaN)); - Assert.AreEqual(".000", String.Format(culture, "{0:.000}", Complex32.Zero)); - Assert.AreEqual("1.100", String.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f))); - Assert.AreEqual("1.100 + 1.100i", String.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f))); + Assert.AreEqual("(NaN, NaN)", String.Format(culture, "{0:.000}", Complex32.NaN)); + Assert.AreEqual("(.000, .000)", String.Format(culture, "{0:.000}", Complex32.Zero)); + Assert.AreEqual("(1.100, .000)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f))); + Assert.AreEqual("(1.100, 1.100)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f))); - Assert.AreEqual("NaN", Complex32.NaN.ToString("#.000", culture)); - Assert.AreEqual("Infinity", Complex32.Infinity.ToString("#.000", culture)); - Assert.AreEqual(".000", Complex32.Zero.ToString("#.000", culture)); - Assert.AreEqual("1.100", new Complex32(1.1f, 0.0f).ToString("#.000", culture)); - Assert.AreEqual("-1.100i", new Complex32(0.0f, -1.1f).ToString("#.000", culture)); - Assert.AreEqual("1.100i", new Complex32(0.0f, 1.1f).ToString("#.000", culture)); - Assert.AreEqual("1.100 + 1.100i", new Complex32(1.1f, 1.1f).ToString("#.000", culture)); + Assert.AreEqual("(NaN, NaN)", Complex32.NaN.ToString("#.000", culture)); + Assert.AreEqual("(Infinity, Infinity)", Complex32.Infinity.ToString("#.000", culture)); + Assert.AreEqual("(.000, .000)", Complex32.Zero.ToString("#.000", culture)); + Assert.AreEqual("(1.100, .000)", new Complex32(1.1f, 0.0f).ToString("#.000", culture)); + Assert.AreEqual("(.000, -1.100)", new Complex32(0.0f, -1.1f).ToString("#.000", culture)); + Assert.AreEqual("(.000, 1.100)", new Complex32(0.0f, 1.1f).ToString("#.000", culture)); + Assert.AreEqual("(1.100, 1.100)", new Complex32(1.1f, 1.1f).ToString("#.000", culture)); } [Test] diff --git a/src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs new file mode 100644 index 00000000..a60a3893 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs @@ -0,0 +1,90 @@ +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.IO +{ + using System; + using System.Globalization; + using System.Numerics; + using System.IO; + using LinearAlgebra.Complex; + using LinearAlgebra.IO; + using MbUnit.Framework; + + [TestFixture] + public class DelimitedWriterTests + { + [Test] + public void CanWriteCommaDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } }); + var writer = new DelimitedWriter(','); + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1.1, 1.1),(2.2, 2.2),(3.3, 3.3) +(4.4, 4.4),(5.5, 5.5),(6.6, 6.6) +(7.7, 7.7),(8.8, 8.8),(9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWritePeriodDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } }); + var culture = new CultureInfo("tr-TR"); + var writer = new DelimitedWriter('.') + { + CultureInfo = culture + }; + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1,1, 1,1).(2,2, 2,2).(3,3, 3,3) +(4,4, 4,4).(5,5, 5,5).(6,6, 6,6) +(7,7, 7,7).(8,8, 8,8).(9,9, 9,9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWriteSpaceDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } }); + var writer = new DelimitedWriter(' '); + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1.1, 1.1) (2.2, 2.2) (3.3, 3.3) +(4.4, 4.4) (5.5, 5.5) (6.6, 6.6) +(7.7, 7.7) (8.8, 8.8) (9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWriteTabDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex(1.1, 1.1), new Complex(2.2, 2.2), new Complex(3.3, 3.3) }, { new Complex(4.4, 4.4), new Complex(5.5, 5.5), new Complex(6.6, 6.6) }, { new Complex(7.7, 7.7), new Complex(8.8, 8.8), new Complex(9.9, 9.9) } }); + var headers = new[] { "a", "b", "c" }; + var writer = new DelimitedWriter('\t') + { + ColumnHeaders = headers + }; + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + var expected = "a\tb\tc" + + Environment.NewLine + + "(1.1, 1.1)\t(2.2, 2.2)\t(3.3, 3.3)" + + Environment.NewLine + + "(4.4, 4.4)\t(5.5, 5.5)\t(6.6, 6.6)" + + Environment.NewLine + + "(7.7, 7.7)\t(8.8, 8.8)\t(9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs b/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs index 76527b5e..103c5805 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorTest.TextHandling.cs @@ -39,16 +39,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public class DenseVectorTextHandlingTest { [Test] - [Row("2", "2")] - [Row("(3)", "3")] - [Row("[1,2,3]", "1,2,3")] - [Row(" [ 1.1 , 2.1 , 3.1 ] ", "1.1,2.1,3.1")] - [Row(" [ -1.1 , 2.1 , +3.1 ] ", "-1.1,2.1,3.1")] - [Row(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] - [Row("[1+1i,2+1i,3+1i]", "1 + 1i,2 + 1i,3 + 1i")] - [Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "1.1 + 1i,2.1 + 1i,3.1 + 1i")] - [Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "-1.1 + 1i,2.1 - 1i,3.1 + 1i")] - [Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "1.2 + 2.3i,3.4 + 4.5i,5.6 + 6.7i")] + [Row("2", "(2, 0)")] + [Row("(3)", "(3, 0)")] + [Row("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] + [Row(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] + [Row(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] + [Row(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] + [Row("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] + [Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] + [Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] + [Row(" [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; @@ -58,9 +58,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 } [Test] - [Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "1.2 + 1i,3.4 + 1i,5.6 + 1i", "en-US")] - [Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "1.2 + 1i;3.4 + 1i;5.6 + 1i", "de-CH")] - [Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "1,2 + 1i;3,4 + 1i;5,6 + 1i", "de-DE")] + [Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] + [Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] + [Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] public void CanParseComplexDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture) { var formatProvider = CultureInfo.GetCultureInfo(culture); diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/IO/DelimitedWriterTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/IO/DelimitedWriterTests.cs new file mode 100644 index 00000000..b65a3737 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Complex32/IO/DelimitedWriterTests.cs @@ -0,0 +1,90 @@ +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32.IO +{ + using System; + using System.Globalization; + using System.IO; + using LinearAlgebra.Complex32; + using Numerics; + using LinearAlgebra.IO; + using MbUnit.Framework; + + [TestFixture] + public class DelimitedWriterTests + { + [Test] + public void CanWriteCommaDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } }); + var writer = new DelimitedWriter(','); + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1.1, 1.1),(2.2, 2.2),(3.3, 3.3) +(4.4, 4.4),(5.5, 5.5),(6.6, 6.6) +(7.7, 7.7),(8.8, 8.8),(9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWritePeriodDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } }); + var culture = new CultureInfo("tr-TR"); + var writer = new DelimitedWriter('.') + { + CultureInfo = culture + }; + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1,1, 1,1).(2,2, 2,2).(3,3, 3,3) +(4,4, 4,4).(5,5, 5,5).(6,6, 6,6) +(7,7, 7,7).(8,8, 8,8).(9,9, 9,9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWriteSpaceDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } }); + var writer = new DelimitedWriter(' '); + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + const string expected = @"(1.1, 1.1) (2.2, 2.2) (3.3, 3.3) +(4.4, 4.4) (5.5, 5.5) (6.6, 6.6) +(7.7, 7.7) (8.8, 8.8) (9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + + [Test] + public void CanWriteTabDelimitedData() + { + var matrix = new DenseMatrix(new[,] { { new Complex32(1.1f, 1.1f), new Complex32(2.2f, 2.2f), new Complex32(3.3f, 3.3f) }, { new Complex32(4.4f, 4.4f), new Complex32(5.5f, 5.5f), new Complex32(6.6f, 6.6f) }, { new Complex32(7.7f, 7.7f), new Complex32(8.8f, 8.8f), new Complex32(9.9f, 9.9f) } }); + var headers = new[] { "a", "b", "c" }; + var writer = new DelimitedWriter('\t') + { + ColumnHeaders = headers + }; + var stream = new MemoryStream(); + writer.WriteMatrix(matrix, stream); + var data = stream.ToArray(); + var reader = new StreamReader(new MemoryStream(data)); + var text = reader.ReadToEnd(); + var expected = "a\tb\tc" + + Environment.NewLine + + "(1.1, 1.1)\t(2.2, 2.2)\t(3.3, 3.3)" + + Environment.NewLine + + "(4.4, 4.4)\t(5.5, 5.5)\t(6.6, 6.6)" + + Environment.NewLine + + "(7.7, 7.7)\t(8.8, 8.8)\t(9.9, 9.9)"; + Assert.AreEqual(expected, text); + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs index d647708d..c9604bb9 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.TextHandling.cs @@ -38,16 +38,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public class SparseVectorTextHandlingTest { [Test] - [Row("2", "2")] - [Row("(3)", "3")] - [Row("[1,2,3]", "1,2,3")] - [Row(" [ 1.1 , 2.1 , 3.1 ] ", "1.1,2.1,3.1")] - [Row(" [ -1.1 , 2.1 , +3.1 ] ", "-1.1,2.1,3.1")] - [Row(" [1.2,3.4 , 5.6] ", "1.2,3.4,5.6")] - [Row("[1+1i,2+1i,3+1i]", "1 + 1i,2 + 1i,3 + 1i")] - [Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "1.1 + 1i,2.1 + 1i,3.1 + 1i")] - [Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "-1.1 + 1i,2.1 - 1i,3.1 + 1i")] - [Row(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "1.2 + 2.3i,3.4 + 4.5i,5.6 + 6.7i")] + [Row("2", "(2, 0)")] + [Row("(3)", "(3, 0)")] + [Row("[1,2,3]", "(1, 0),(2, 0),(3, 0)")] + [Row(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")] + [Row(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")] + [Row(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")] + [Row("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")] + [Row(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")] + [Row(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")] + [Row(" [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; @@ -57,9 +57,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 } [Test] - [Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "1.2 + 1i,3.4 + 1i,5.6 + 1i", "en-US")] - [Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "1.2 + 1i;3.4 + 1i;5.6 + 1i", "de-CH")] - [Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "1,2 + 1i;3,4 + 1i;5,6 + 1i", "de-DE")] + [Row(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")] + [Row(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")] + [Row(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")] public void CanParseComplexSparseVectorsWithCulture(string stringToParse, string expectedToString, string culture) { var formatProvider = CultureInfo.GetCultureInfo(culture); diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs index 7171cd12..47b3afa2 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs @@ -77,7 +77,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 var vector = CreateVector(Data); var str = vector.ToString(); var sep = CultureInfo.CurrentCulture.TextInfo.ListSeparator; - Assert.AreEqual(string.Format("1 + 1i{0}2 + 1i{0}3 + 1i{0}4 + 1i{0}5 + 1i", sep), str); + Assert.AreEqual(string.Format("(1, 1){0}(2, 1){0}(3, 1){0}(4, 1){0}(5, 1)", sep), str); } [Test] diff --git a/src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs b/src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs index 1dc493c6..62cef298 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/IO/DelimitedWriterTests.cs @@ -3,9 +3,8 @@ using System; using System.Globalization; using System.IO; - using System.Text; using LinearAlgebra.Double; - using LinearAlgebra.Double.IO; + using LinearAlgebra.IO; using MbUnit.Framework; [TestFixture] @@ -15,7 +14,7 @@ public void CanWriteCommaDelimitedData() { var matrix = new DenseMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } }); - var writer = new DelimitedWriter(','); + var writer = new DelimitedWriter(','); var stream = new MemoryStream(); writer.WriteMatrix(matrix, stream); var data = stream.ToArray(); @@ -32,7 +31,7 @@ { var matrix = new DenseMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } }); var culture = new CultureInfo("tr-TR"); - var writer = new DelimitedWriter('.') + var writer = new DelimitedWriter('.') { CultureInfo = culture }; @@ -51,7 +50,7 @@ public void CanWriteSpaceDelimitedData() { var matrix = new SparseMatrix(new[,] { { 1.1, 0, 0 }, { 0, 5.5, 0 }, { 0, 0, 9.9 } }); - var writer = new DelimitedWriter(' '); + var writer = new DelimitedWriter(' '); var stream = new MemoryStream(); writer.WriteMatrix(matrix, stream); var data = stream.ToArray(); @@ -68,7 +67,7 @@ { var matrix = new UserDefinedMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } }); var headers = new[] { "a", "b", "c" }; - var writer = new DelimitedWriter('\t') + var writer = new DelimitedWriter('\t') { ColumnHeaders = headers }; diff --git a/src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs b/src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs index 38ea6e58..d819220e 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/IO/DelimitedWriterTests.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Text; + using LinearAlgebra.IO; using LinearAlgebra.Single; using LinearAlgebra.Single.IO; using MbUnit.Framework; @@ -15,7 +16,7 @@ public void CanWriteCommaDelimitedData() { var matrix = new DenseMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } }); - var writer = new DelimitedWriter(','); + var writer = new DelimitedWriter(','); var stream = new MemoryStream(); writer.WriteMatrix(matrix, stream); var data = stream.ToArray(); @@ -32,7 +33,7 @@ { var matrix = new DenseMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } }); var culture = new CultureInfo("tr-TR"); - var writer = new DelimitedWriter('.') + var writer = new DelimitedWriter('.') { CultureInfo = culture }; @@ -51,7 +52,7 @@ public void CanWriteSpaceDelimitedData() { var matrix = new SparseMatrix(new[,] { { 1.1f, 0, 0 }, { 0, 5.5f, 0 }, { 0, 0, 9.9f } }); - var writer = new DelimitedWriter(' '); + var writer = new DelimitedWriter(' '); var stream = new MemoryStream(); writer.WriteMatrix(matrix, stream); var data = stream.ToArray(); @@ -68,7 +69,7 @@ { var matrix = new UserDefinedMatrix(new[,] { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } }); var headers = new[] { "a", "b", "c" }; - var writer = new DelimitedWriter('\t') + var writer = new DelimitedWriter('\t') { ColumnHeaders = headers }; diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 08ec4cf3..8968a933 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -136,6 +136,7 @@ + @@ -178,6 +179,7 @@ +