@@ -32,17 +32,8 @@ namespace UnitsNet.Tests
32
32
[ TestFixture ]
33
33
public class UnitSystemTests
34
34
{
35
- private CultureInfo _originalUICulture ;
36
35
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 ;
46
37
47
38
[ SetUp ]
48
39
public void Setup ( )
@@ -60,6 +51,30 @@ public void Teardown()
60
51
Thread . CurrentThread . CurrentCulture = _originalCulture ;
61
52
}
62
53
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
+
63
78
#region Missing Abbreviations
64
79
65
80
[ Test ]
@@ -79,7 +94,8 @@ public void AllUnitAbbreviationsImplemented([Values("en-US", "nb-NO", "ru-RU")]
79
94
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < AngleUnit > ( ) ) )
80
95
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < AreaUnit > ( ) ) )
81
96
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < DurationUnit > ( ) ) )
82
- . Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < ElectricPotentialUnit > ( ) ) )
97
+ . Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName ,
98
+ EnumUtils . GetEnumValues < ElectricPotentialUnit > ( ) ) )
83
99
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < FlowUnit > ( ) ) )
84
100
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < ForceUnit > ( ) ) )
85
101
. Concat ( GetUnitTypesWithMissingAbbreviations ( cultureName , EnumUtils . GetEnumValues < LengthUnit > ( ) ) )
@@ -99,16 +115,17 @@ public void AllUnitAbbreviationsImplemented([Values("en-US", "nb-NO", "ru-RU")]
99
115
if ( unitValuesMissingAbbreviations . Any ( ) )
100
116
{
101
117
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 ( ) ) ;
105
121
106
122
Assert . Inconclusive ( "Failed, but skipping error for localization: " + message ) ;
107
123
}
108
124
//Assert.IsEmpty(unitsMissingAbbreviations, message);
109
125
}
110
126
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 )
112
129
where TUnit : /*Enum constraint hack*/ struct , IComparable , IFormattable
113
130
{
114
131
UnitSystem unitSystem = UnitSystem . GetCached ( new CultureInfo ( cultureName ) ) ;
@@ -269,8 +286,10 @@ public void CommaDigitGroupingCultureFormatting(string culture)
269
286
270
287
// Feet/Inch and Stone/Pound combinations are only used (customarily) in the US, UK and maybe Ireland - all English speaking countries.
271
288
// 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 ) ) ) ;
274
293
}
275
294
276
295
// These cultures use a thin space in digit grouping
@@ -344,35 +363,21 @@ public string CustomNumberOfSignificantDigitsAfterRadixFormatting(int significan
344
363
[ TestCase ( 0.00299999999 , 4 , Result = "0.003 m" ) ]
345
364
[ TestCase ( 0.0003000001 , 2 , Result = "3e-04 m" ) ]
346
365
[ 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 )
348
368
{
349
369
return Length . FromMeters ( value ) . ToString ( LengthUnit . Meter , null , maxSignificantDigitsAfterRadix ) ;
350
370
}
351
371
352
372
#endregion
353
373
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
-
369
374
#region ToString Formatting Intervals
370
375
371
376
[ Test ]
372
377
public void NegativeInfinityFormatting ( )
373
378
{
374
379
Assert . That ( Length . FromMeters ( Double . NegativeInfinity ) . ToString ( ) ,
375
- Is . EqualTo ( "-Infinity m" ) ) ;
380
+ Is . EqualTo ( "-Infinity m" ) ) ;
376
381
}
377
382
378
383
// Any value in the interval (-inf ≤ x < 1e-03] is formatted in scientific notation
@@ -417,14 +422,14 @@ public string ScientificNotationUpperIntervalFormatting(double value)
417
422
public void PositiveInfinityFormatting ( )
418
423
{
419
424
Assert . That ( Length . FromMeters ( Double . PositiveInfinity ) . ToString ( ) ,
420
- Is . EqualTo ( "Infinity m" ) ) ;
425
+ Is . EqualTo ( "Infinity m" ) ) ;
421
426
}
422
427
423
428
[ Test ]
424
429
public void NotANumberFormatting ( )
425
430
{
426
431
Assert . That ( Length . FromMeters ( Double . NaN ) . ToString ( ) ,
427
- Is . EqualTo ( "NaN m" ) ) ;
432
+ Is . EqualTo ( "NaN m" ) ) ;
428
433
}
429
434
430
435
#endregion
0 commit comments