Skip to content

Commit dd9412c

Browse files
committed
UnitSystemTests: R# cleanup
1 parent b215ac5 commit dd9412c

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

UnitsNet.Tests/UnitSystemTests.cs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,8 @@ namespace UnitsNet.Tests
3232
[TestFixture]
3333
public class UnitSystemTests
3434
{
35-
private CultureInfo _originalUICulture;
3635
private CultureInfo _originalCulture;
37-
38-
private enum CustomUnit
39-
{
40-
// ReSharper disable UnusedMember.Local
41-
Undefined = 0,
42-
Unit1,
43-
Unit2
44-
// ReSharper restore UnusedMember.Local
45-
}
36+
private CultureInfo _originalUICulture;
4637

4738
[SetUp]
4839
public void Setup()
@@ -60,6 +51,30 @@ public void Teardown()
6051
Thread.CurrentThread.CurrentCulture = _originalCulture;
6152
}
6253

54+
#region Default ToString Formatting
55+
56+
// The default, parameterless ToString() method uses 2 sigifnificant digits after the radix point.
57+
[TestCase(0, Result = "0 m")]
58+
[TestCase(0.1, Result = "0.1 m")]
59+
[TestCase(0.11, Result = "0.11 m")]
60+
[TestCase(0.111234, Result = "0.11 m")]
61+
[TestCase(0.115, Result = "0.12 m")]
62+
public string DefaultToStringFormatting(double value)
63+
{
64+
return Length.FromMeters(value).ToString();
65+
}
66+
67+
#endregion
68+
69+
private enum CustomUnit
70+
{
71+
// ReSharper disable UnusedMember.Local
72+
Undefined = 0,
73+
Unit1,
74+
Unit2
75+
// ReSharper restore UnusedMember.Local
76+
}
77+
6378
#region Missing Abbreviations
6479

6580
[Test]
@@ -79,7 +94,8 @@ public void AllUnitAbbreviationsImplemented([Values("en-US", "nb-NO", "ru-RU")]
7994
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<AngleUnit>()))
8095
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<AreaUnit>()))
8196
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<DurationUnit>()))
82-
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<ElectricPotentialUnit>()))
97+
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName,
98+
EnumUtils.GetEnumValues<ElectricPotentialUnit>()))
8399
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<FlowUnit>()))
84100
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<ForceUnit>()))
85101
.Concat(GetUnitTypesWithMissingAbbreviations(cultureName, EnumUtils.GetEnumValues<LengthUnit>()))
@@ -99,16 +115,17 @@ public void AllUnitAbbreviationsImplemented([Values("en-US", "nb-NO", "ru-RU")]
99115
if (unitValuesMissingAbbreviations.Any())
100116
{
101117
string message = "Units missing abbreviations: " +
102-
string.Join(", ",
103-
unitValuesMissingAbbreviations.Select(
104-
unitValue => unitValue.GetType().Name + "." + unitValue).ToArray());
118+
string.Join(", ",
119+
unitValuesMissingAbbreviations.Select(
120+
unitValue => unitValue.GetType().Name + "." + unitValue).ToArray());
105121

106122
Assert.Inconclusive("Failed, but skipping error for localization: " + message);
107123
}
108124
//Assert.IsEmpty(unitsMissingAbbreviations, message);
109125
}
110126

111-
private static IEnumerable<object> GetUnitTypesWithMissingAbbreviations<TUnit>(string cultureName, IEnumerable<TUnit> unitValues)
127+
private static IEnumerable<object> GetUnitTypesWithMissingAbbreviations<TUnit>(string cultureName,
128+
IEnumerable<TUnit> unitValues)
112129
where TUnit : /*Enum constraint hack*/ struct, IComparable, IFormattable
113130
{
114131
UnitSystem unitSystem = UnitSystem.GetCached(new CultureInfo(cultureName));
@@ -269,8 +286,10 @@ public void CommaDigitGroupingCultureFormatting(string culture)
269286

270287
// Feet/Inch and Stone/Pound combinations are only used (customarily) in the US, UK and maybe Ireland - all English speaking countries.
271288
// FeetInches returns a whole number of feet, with the remainder expressed (rounded) in inches. Same for SonePounds.
272-
Assert.AreEqual("2,222 ft 3 in", Length.FromFeetInches(2222, 3).FeetInches.ToString(new CultureInfo(culture)));
273-
Assert.AreEqual("3,333 st 7 lb", Mass.FromStonePounds(3333, 7).StonePounds.ToString(new CultureInfo(culture)));
289+
Assert.AreEqual("2,222 ft 3 in",
290+
Length.FromFeetInches(2222, 3).FeetInches.ToString(new CultureInfo(culture)));
291+
Assert.AreEqual("3,333 st 7 lb",
292+
Mass.FromStonePounds(3333, 7).StonePounds.ToString(new CultureInfo(culture)));
274293
}
275294

276295
// These cultures use a thin space in digit grouping
@@ -344,35 +363,21 @@ public string CustomNumberOfSignificantDigitsAfterRadixFormatting(int significan
344363
[TestCase(0.00299999999, 4, Result = "0.003 m")]
345364
[TestCase(0.0003000001, 2, Result = "3e-04 m")]
346365
[TestCase(0.0003000001, 4, Result = "3e-04 m")]
347-
public string RoundingErrorsWithSignificantDigitsAfterRadixFormatting(double value, int maxSignificantDigitsAfterRadix)
366+
public string RoundingErrorsWithSignificantDigitsAfterRadixFormatting(double value,
367+
int maxSignificantDigitsAfterRadix)
348368
{
349369
return Length.FromMeters(value).ToString(LengthUnit.Meter, null, maxSignificantDigitsAfterRadix);
350370
}
351371

352372
#endregion
353373

354-
#region Default ToString Formatting
355-
356-
// The default, parameterless ToString() method uses 2 sigifnificant digits after the radix point.
357-
[TestCase(0, Result = "0 m")]
358-
[TestCase(0.1, Result = "0.1 m")]
359-
[TestCase(0.11, Result = "0.11 m")]
360-
[TestCase(0.111234, Result = "0.11 m")]
361-
[TestCase(0.115, Result = "0.12 m")]
362-
public string DefaultToStringFormatting(double value)
363-
{
364-
return Length.FromMeters(value).ToString();
365-
}
366-
367-
#endregion
368-
369374
#region ToString Formatting Intervals
370375

371376
[Test]
372377
public void NegativeInfinityFormatting()
373378
{
374379
Assert.That(Length.FromMeters(Double.NegativeInfinity).ToString(),
375-
Is.EqualTo("-Infinity m"));
380+
Is.EqualTo("-Infinity m"));
376381
}
377382

378383
// Any value in the interval (-inf ≤ x < 1e-03] is formatted in scientific notation
@@ -417,14 +422,14 @@ public string ScientificNotationUpperIntervalFormatting(double value)
417422
public void PositiveInfinityFormatting()
418423
{
419424
Assert.That(Length.FromMeters(Double.PositiveInfinity).ToString(),
420-
Is.EqualTo("Infinity m"));
425+
Is.EqualTo("Infinity m"));
421426
}
422427

423428
[Test]
424429
public void NotANumberFormatting()
425430
{
426431
Assert.That(Length.FromMeters(Double.NaN).ToString(),
427-
Is.EqualTo("NaN m"));
432+
Is.EqualTo("NaN m"));
428433
}
429434

430435
#endregion

0 commit comments

Comments
 (0)