Skip to content

Commit bf821b9

Browse files
committed
Code maintenance
1 parent 12bf858 commit bf821b9

71 files changed

Lines changed: 851 additions & 873 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Data.Tests/Matlab/MatlabWriterTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MatlabWriterTests
4343
[Test]
4444
public void WriteBadMatricesThrowsArgumentException()
4545
{
46-
Matrix<float> matrix = Matrix<float>.Build.Dense(1, 1);
46+
var matrix = Matrix<float>.Build.Dense(1, 1);
4747
var filePath = Path.GetTempFileName();
4848
try
4949
{
@@ -64,24 +64,24 @@ public void WriteBadMatricesThrowsArgumentException()
6464
[Test]
6565
public void CanWriteDoubleMatrices()
6666
{
67-
Matrix<double> mat1 = Matrix<double>.Build.Dense(5, 5);
67+
var mat1 = Matrix<double>.Build.Dense(5, 5);
6868
for (var i = 0; i < mat1.ColumnCount; i++)
6969
{
7070
mat1[i, i] = i + .1;
7171
}
7272

73-
Matrix<double> mat2 = Matrix<double>.Build.Dense(4, 5);
73+
var mat2 = Matrix<double>.Build.Dense(4, 5);
7474
for (var i = 0; i < mat2.RowCount; i++)
7575
{
7676
mat2[i, i] = i + .1;
7777
}
7878

79-
Matrix<double> mat3 = Matrix<double>.Build.Sparse(5, 4);
79+
var mat3 = Matrix<double>.Build.Sparse(5, 4);
8080
mat3[0, 0] = 1.1;
8181
mat3[0, 2] = 2.2;
8282
mat3[4, 3] = 3.3;
8383

84-
Matrix<double> mat4 = Matrix<double>.Build.Sparse(3, 5);
84+
var mat4 = Matrix<double>.Build.Sparse(3, 5);
8585
mat4[0, 0] = 1.1;
8686
mat4[0, 2] = 2.2;
8787
mat4[2, 4] = 3.3;
@@ -114,24 +114,24 @@ public void CanWriteDoubleMatrices()
114114
[Test]
115115
public void CanWriteFloatMatrices()
116116
{
117-
Matrix<float> mat1 = Matrix<float>.Build.Dense(5, 3);
117+
var mat1 = Matrix<float>.Build.Dense(5, 3);
118118
for (var i = 0; i < mat1.ColumnCount; i++)
119119
{
120120
mat1[i, i] = i + .1f;
121121
}
122122

123-
Matrix<float> mat2 = Matrix<float>.Build.Dense(4, 5);
123+
var mat2 = Matrix<float>.Build.Dense(4, 5);
124124
for (var i = 0; i < mat2.RowCount; i++)
125125
{
126126
mat2[i, i] = i + .1f;
127127
}
128128

129-
Matrix<float> mat3 = Matrix<float>.Build.Sparse(5, 4);
129+
var mat3 = Matrix<float>.Build.Sparse(5, 4);
130130
mat3[0, 0] = 1.1f;
131131
mat3[0, 2] = 2.2f;
132132
mat3[4, 3] = 3.3f;
133133

134-
Matrix<float> mat4 = Matrix<float>.Build.Sparse(3, 5);
134+
var mat4 = Matrix<float>.Build.Sparse(3, 5);
135135
mat4[0, 0] = 1.1f;
136136
mat4[0, 2] = 2.2f;
137137
mat4[2, 4] = 3.3f;
@@ -167,24 +167,24 @@ public void CanWriteFloatMatrices()
167167
[Test]
168168
public void CanWriteComplex32Matrices()
169169
{
170-
Matrix<Complex32> mat1 = Matrix<Complex32>.Build.Dense(5, 3);
170+
var mat1 = Matrix<Complex32>.Build.Dense(5, 3);
171171
for (var i = 0; i < mat1.ColumnCount; i++)
172172
{
173173
mat1[i, i] = new Complex32(i + .1f, i + .1f);
174174
}
175175

176-
Matrix<Complex32> mat2 = Matrix<Complex32>.Build.Dense(4, 5);
176+
var mat2 = Matrix<Complex32>.Build.Dense(4, 5);
177177
for (var i = 0; i < mat2.RowCount; i++)
178178
{
179179
mat2[i, i] = new Complex32(i + .1f, i + .1f);
180180
}
181181

182-
Matrix<Complex32> mat3 = Matrix<Complex32>.Build.Sparse(5, 4);
182+
var mat3 = Matrix<Complex32>.Build.Sparse(5, 4);
183183
mat3[0, 0] = new Complex32(1.1f, 1.1f);
184184
mat3[0, 2] = new Complex32(2.2f, 2.2f);
185185
mat3[4, 3] = new Complex32(3.3f, 3.3f);
186186

187-
Matrix<Complex32> mat4 = Matrix<Complex32>.Build.Sparse(3, 5);
187+
var mat4 = Matrix<Complex32>.Build.Sparse(3, 5);
188188
mat4[0, 0] = new Complex32(1.1f, 1.1f);
189189
mat4[0, 2] = new Complex32(2.2f, 2.2f);
190190
mat4[2, 4] = new Complex32(3.3f, 3.3f);
@@ -220,24 +220,24 @@ public void CanWriteComplex32Matrices()
220220
[Test]
221221
public void CanWriteComplexMatrices()
222222
{
223-
Matrix<Complex> mat1 = Matrix<Complex>.Build.Dense(5, 3);
223+
var mat1 = Matrix<Complex>.Build.Dense(5, 3);
224224
for (var i = 0; i < mat1.ColumnCount; i++)
225225
{
226226
mat1[i, i] = new Complex(i + .1, i + .1);
227227
}
228228

229-
Matrix<Complex> mat2 = Matrix<Complex>.Build.Dense(4, 5);
229+
var mat2 = Matrix<Complex>.Build.Dense(4, 5);
230230
for (var i = 0; i < mat2.RowCount; i++)
231231
{
232232
mat2[i, i] = new Complex(i + .1, i + .1);
233233
}
234234

235-
Matrix<Complex> mat3 = Matrix<Complex>.Build.Sparse(5, 4);
235+
var mat3 = Matrix<Complex>.Build.Sparse(5, 4);
236236
mat3[0, 0] = new Complex(1.1, 1.1);
237237
mat3[0, 2] = new Complex(2.2, 2.2);
238238
mat3[4, 3] = new Complex(3.3, 3.3);
239239

240-
Matrix<Complex> mat4 = Matrix<Complex>.Build.Sparse(3, 5);
240+
var mat4 = Matrix<Complex>.Build.Sparse(3, 5);
241241
mat4[0, 0] = new Complex(1.1, 1.1);
242242
mat4[0, 2] = new Complex(2.2, 2.2);
243243
mat4[2, 4] = new Complex(3.3, 3.3);

src/Data.Tests/Text/DelimitedWriterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public void CanWriteCommaDelimitedDataWithMissingValues()
177177
[Test]
178178
public void CanWriteTabDelimitedDataWithMissingValues()
179179
{
180-
var matrix = DenseMatrix.OfArray(new[,] { { 1.1, Double.NaN, 0 }, { 0, 5.5, 0 }, { Double.NaN, Double.NaN, 9.9 } });
180+
var matrix = DenseMatrix.OfArray(new[,] { { 1.1, double.NaN, 0 }, { 0, 5.5, 0 }, { double.NaN, double.NaN, 9.9 } });
181181
var stream = new MemoryStream();
182-
DelimitedWriter.Write(stream, matrix, "\t", missingValue: Double.NaN);
182+
DelimitedWriter.Write(stream, matrix, "\t", missingValue: double.NaN);
183183
var data = stream.ToArray();
184184
var reader = new StreamReader(new MemoryStream(data));
185185
var text = reader.ReadToEnd();
@@ -189,4 +189,4 @@ public void CanWriteTabDelimitedDataWithMissingValues()
189189
Assert.AreEqual(expected, text);
190190
}
191191
}
192-
}
192+
}

src/Numerics.Tests/ComplexTests/Complex32Test.TextHandling.cs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public class Complex32TextHandlingTest
5151
[TestCase(0, -2, "(0, -2)")]
5252
[TestCase(0, 2, "(0, 2)")]
5353
[TestCase(0, 0, "(0, 0)")]
54-
[TestCase(Single.NaN, Single.NaN, "({1}, {1})")]
55-
[TestCase(Single.NaN, 0, "({1}, 0)")]
56-
[TestCase(0, Single.NaN, "(0, {1})")]
57-
[TestCase(Single.PositiveInfinity, Single.PositiveInfinity, "({2}, {2})")]
54+
[TestCase(float.NaN, float.NaN, "({1}, {1})")]
55+
[TestCase(float.NaN, 0, "({1}, 0)")]
56+
[TestCase(0, float.NaN, "(0, {1})")]
57+
[TestCase(float.PositiveInfinity, float.PositiveInfinity, "({2}, {2})")]
5858
[TestCase(1.1f, 0, "(1{0}1, 0)")]
5959
[TestCase(-1.1f, 0, "(-1{0}1, 0)")]
6060
[TestCase(0, 1.1f, "(0, 1{0}1)")]
@@ -65,7 +65,7 @@ public void CanFormatComplexToString(float real, float imag, string expected)
6565
var numberFormat = NumberFormatInfo.CurrentInfo;
6666
var a = new Complex32(real, imag);
6767
Assert.AreEqual(
68-
String.Format(
68+
string.Format(
6969
expected,
7070
numberFormat.NumberDecimalSeparator,
7171
numberFormat.NaNSymbol,
@@ -92,11 +92,11 @@ public void CanFormatComplexToStringWithCulture(string cultureName, string numbe
9292
Assert.AreEqual("(" + nan + ", " + nan + ")", Complex32.NaN.ToString(provider));
9393
Assert.AreEqual("(" + infinity + ", " + infinity + ")", Complex32.PositiveInfinity.ToString(provider));
9494
Assert.AreEqual("(0, 0)", Complex32.Zero.ToString(provider));
95-
Assert.AreEqual("(" + String.Format("{0}", number) + ", 0)", new Complex32(1.1f, 0.0f).ToString(provider));
96-
Assert.AreEqual("(" + String.Format("-{0}", number) + ", 0)", new Complex32(-1.1f, 0f).ToString(provider));
97-
Assert.AreEqual("(0, " + String.Format("-{0}", number) + ")", new Complex32(0.0f, -1.1f).ToString(provider));
98-
Assert.AreEqual("(0, " + String.Format("{0}", number) + ")", new Complex32(0.0f, 1.1f).ToString(provider));
99-
Assert.AreEqual("(" + String.Format("{0}", number) + ", " + String.Format("{0}", number) + ")", new Complex32(1.1f, 1.1f).ToString(provider));
95+
Assert.AreEqual("(" + string.Format("{0}", number) + ", 0)", new Complex32(1.1f, 0.0f).ToString(provider));
96+
Assert.AreEqual("(" + string.Format("-{0}", number) + ", 0)", new Complex32(-1.1f, 0f).ToString(provider));
97+
Assert.AreEqual("(0, " + string.Format("-{0}", number) + ")", new Complex32(0.0f, -1.1f).ToString(provider));
98+
Assert.AreEqual("(0, " + string.Format("{0}", number) + ")", new Complex32(0.0f, 1.1f).ToString(provider));
99+
Assert.AreEqual("(" + string.Format("{0}", number) + ", " + string.Format("{0}", number) + ")", new Complex32(1.1f, 1.1f).ToString(provider));
100100
}
101101

102102
/// <summary>
@@ -105,11 +105,11 @@ public void CanFormatComplexToStringWithCulture(string cultureName, string numbe
105105
[Test]
106106
public void CanFormatComplexToStringWithFormat()
107107
{
108-
Assert.AreEqual("(0, 0)", String.Format("{0:G}", Complex32.Zero));
109-
Assert.AreEqual("(1, 2)", String.Format("{0:G}", new Complex32(1, 2)));
110-
Assert.AreEqual("(001, 002)", String.Format("{0:000;minus 000;zero}", new Complex32(1, 2)));
111-
Assert.AreEqual("(zero, minus 002)", String.Format("{0:000;minus 000;zero}", new Complex32(0, -2)));
112-
Assert.AreEqual("(zero, zero)", String.Format("{0:000;minus 000;zero}", Complex32.Zero));
108+
Assert.AreEqual("(0, 0)", string.Format("{0:G}", Complex32.Zero));
109+
Assert.AreEqual("(1, 2)", string.Format("{0:G}", new Complex32(1, 2)));
110+
Assert.AreEqual("(001, 002)", string.Format("{0:000;minus 000;zero}", new Complex32(1, 2)));
111+
Assert.AreEqual("(zero, minus 002)", string.Format("{0:000;minus 000;zero}", new Complex32(0, -2)));
112+
Assert.AreEqual("(zero, zero)", string.Format("{0:000;minus 000;zero}", Complex32.Zero));
113113

114114
Assert.AreEqual("(0, 0)", Complex32.Zero.ToString("G"));
115115
Assert.AreEqual("(1, 2)", new Complex32(1, 2).ToString("G"));
@@ -126,10 +126,10 @@ public void CanFormatComplexToStringWithFormatInvariant()
126126
{
127127
var culture = CultureInfo.InvariantCulture;
128128

129-
Assert.AreEqual("(NaN, NaN)", String.Format(culture, "{0:.000}", Complex32.NaN));
130-
Assert.AreEqual("(.000, .000)", String.Format(culture, "{0:.000}", Complex32.Zero));
131-
Assert.AreEqual("(1.100, .000)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f)));
132-
Assert.AreEqual("(1.100, 1.100)", String.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f)));
129+
Assert.AreEqual("(NaN, NaN)", string.Format(culture, "{0:.000}", Complex32.NaN));
130+
Assert.AreEqual("(.000, .000)", string.Format(culture, "{0:.000}", Complex32.Zero));
131+
Assert.AreEqual("(1.100, .000)", string.Format(culture, "{0:.000}", new Complex32(1.1f, 0.0f)));
132+
Assert.AreEqual("(1.100, 1.100)", string.Format(culture, "{0:.000}", new Complex32(1.1f, 1.1f)));
133133

134134
Assert.AreEqual("(NaN, NaN)", Complex32.NaN.ToString("#.000", culture));
135135
Assert.AreEqual("(Infinity, Infinity)", Complex32.PositiveInfinity.ToString("#.000", culture));
@@ -193,8 +193,7 @@ public void CanParseStringToComplexWithCulture(string text, float expectedReal,
193193
public void CanTryParseStringToComplexWithInvariant(string str, float expectedReal, float expectedImaginary)
194194
{
195195
var invariantCulture = CultureInfo.InvariantCulture;
196-
Complex32 z;
197-
var ret = Complex32.TryParse(str, invariantCulture, out z);
196+
var ret = Complex32.TryParse(str, invariantCulture, out var z);
198197
Assert.IsTrue(ret);
199198
Assert.AreEqual(expectedReal, z.Real);
200199
Assert.AreEqual(expectedImaginary, z.Imaginary);
@@ -215,11 +214,10 @@ public void IfMissingClosingParenParseThrowsFormatException()
215214
[Test]
216215
public void TryParseCanHandleSymbols()
217216
{
218-
Complex32 z;
219217
var ni = NumberFormatInfo.CurrentInfo;
220218
var separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
221219
var ret = Complex32.TryParse(
222-
ni.NegativeInfinitySymbol + separator + ni.PositiveInfinitySymbol, out z);
220+
ni.NegativeInfinitySymbol + separator + ni.PositiveInfinitySymbol, out var z);
223221
Assert.IsTrue(ret, "A1");
224222
Assert.AreEqual(float.NegativeInfinity, z.Real, "A2");
225223
Assert.AreEqual(float.PositiveInfinity, z.Imaginary, "A3");
@@ -246,7 +244,7 @@ public void TryParseCanHandleSymbols()
246244
Assert.AreEqual(float.MaxValue, z.Real, "E2");
247245
Assert.AreEqual(float.MinValue, z.Imaginary, "E3");
248246
}
249-
247+
250248
/// <summary>
251249
/// Try parse can handle symbols with a culture.
252250
/// </summary>
@@ -258,12 +256,11 @@ public void TryParseCanHandleSymbols()
258256
//[TestCase("he-IL")] Mono 4 Issue
259257
public void TryParseCanHandleSymbolsWithCulture(string cultureName)
260258
{
261-
Complex32 z;
262259
var culture = new CultureInfo(cultureName);
263260
var ni = culture.NumberFormat;
264261
var separator = culture.TextInfo.ListSeparator;
265262
var ret = Complex32.TryParse(
266-
ni.NegativeInfinitySymbol + separator + ni.PositiveInfinitySymbol, culture, out z);
263+
ni.NegativeInfinitySymbol + separator + ni.PositiveInfinitySymbol, culture, out var z);
267264
Assert.IsTrue(ret, "A1");
268265
Assert.AreEqual(float.NegativeInfinity, z.Real, "A2");
269266
Assert.AreEqual(float.PositiveInfinity, z.Imaginary, "A3");
@@ -313,8 +310,7 @@ public void TryParseCanHandleSymbolsWithCulture(string cultureName)
313310
[TestCase("( )")]
314311
public void TryParseReturnsFalseWhenGivenBadValueWithInvariant(string str)
315312
{
316-
Complex32 z;
317-
var ret = Complex32.TryParse(str, CultureInfo.InvariantCulture, out z);
313+
var ret = Complex32.TryParse(str, CultureInfo.InvariantCulture, out var z);
318314
Assert.IsFalse(ret);
319315
Assert.AreEqual(0, z.Real);
320316
Assert.AreEqual(0, z.Imaginary);

src/Numerics.Tests/DistanceTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
// </copyright>
2929

3030
using NUnit.Framework;
31-
using System;
3231

3332
namespace MathNet.Numerics.Tests
3433
{
@@ -82,7 +81,7 @@ public void Jaccard()
8281

8382
Assert.That(Distance.Jaccard(_dp0, _dq0), Is.EqualTo(1));
8483
Assert.That(Distance.Jaccard(_dp1, _dq1), Is.EqualTo(1));
85-
Assert.That(Distance.Jaccard(_dp2, _dq2), Is.EqualTo(Double.NaN));
84+
Assert.That(Distance.Jaccard(_dp2, _dq2), Is.EqualTo(double.NaN));
8685
Assert.That(Distance.Jaccard(_dp3, _dq3), Is.EqualTo(0));
8786
Assert.That(Distance.Jaccard(_dp4, _dq4), Is.EqualTo(0.66666).Within(0.00001));
8887
Assert.That(Distance.Jaccard(_dp5, _dq5), Is.EqualTo(0.9).Within(0.1));
@@ -150,7 +149,7 @@ public void Cosine()
150149

151150
Assert.That(Distance.Cosine(_dp0, _dq0), Is.EqualTo(0.2).Within(0.00001));
152151
Assert.That(Distance.Cosine(_dp1, _dq1), Is.EqualTo(0.029857).Within(0.00001));
153-
Assert.That(Distance.Cosine(_dp2, _dq2), Is.EqualTo(Double.NaN));
152+
Assert.That(Distance.Cosine(_dp2, _dq2), Is.EqualTo(double.NaN));
154153
Assert.That(Distance.Cosine(_dp3, _dq3), Is.EqualTo(0).Within(0.00001));
155154
Assert.That(Distance.Cosine(_dp4, _dq4), Is.EqualTo(0.039354).Within(0.00001));
156155
Assert.That(Distance.Cosine(_dp5, _dq5), Is.EqualTo(0.031026).Within(0.00001));

0 commit comments

Comments
 (0)