@@ -7,6 +7,44 @@ namespace UnitsNet.Tests
7
7
{
8
8
public class UnitMathTests
9
9
{
10
+ [ Fact ]
11
+ public void AbsoluteValueOfZeroReturnsZero ( )
12
+ {
13
+ var quantity = Length . Zero ;
14
+
15
+ var result = quantity . Abs ( ) ;
16
+
17
+ Assert . StrictEqual ( quantity , result ) ;
18
+ }
19
+
20
+ [ Fact ]
21
+ public void AbsoluteValueOfPositiveReturnsSameValue ( )
22
+ {
23
+ var quantity = Length . FromCentimeters ( 1 ) ;
24
+
25
+ var result = quantity . Abs ( ) ;
26
+
27
+ Assert . StrictEqual ( quantity , result ) ;
28
+ }
29
+
30
+ [ Fact ]
31
+ public void AbsoluteValueOfNegativeReturnsPositive ( )
32
+ {
33
+ var quantity = Length . FromCentimeters ( - 1 ) ;
34
+
35
+ var result = quantity . Abs ( ) ;
36
+
37
+ Assert . StrictEqual ( - quantity , result ) ;
38
+ }
39
+
40
+ [ Fact ]
41
+ public void AbsoluteValueOfNullReferenceThrowsException ( )
42
+ {
43
+ IQuantity quantity = null ;
44
+
45
+ Assert . Throws < NullReferenceException > ( ( ) => quantity . Abs ( ) ) ;
46
+ }
47
+
10
48
[ Fact ]
11
49
public void AverageOfDifferentUnitsThrowsException ( )
12
50
{
@@ -23,6 +61,14 @@ public void AverageOfEmptySourceThrowsException()
23
61
Assert . Throws < InvalidOperationException > ( ( ) => units . Average ( LengthUnit . Centimeter ) ) ;
24
62
}
25
63
64
+ [ Fact ]
65
+ public void AverageOfLengthsWithNullValueThrowsException ( )
66
+ {
67
+ var units = new IQuantity [ ] { Length . FromMeters ( 1 ) , null } ;
68
+
69
+ Assert . Throws < NullReferenceException > ( ( ) => units . Average ( LengthUnit . Centimeter ) ) ;
70
+ }
71
+
26
72
[ Fact ]
27
73
public void AverageOfLengthsCalculatesCorrectly ( )
28
74
{
@@ -61,6 +107,18 @@ public void AverageOfLengthsWithSelectorCalculatesCorrectly()
61
107
Assert . Equal ( LengthUnit . Centimeter , average . Unit ) ;
62
108
}
63
109
110
+ [ Fact ]
111
+ public void MaxOfTwoLengthsReturnsTheLargestValue ( )
112
+ {
113
+ var firstValue = Length . FromMeters ( 1 ) ;
114
+ var secondValue = Length . FromCentimeters ( 50 ) ;
115
+
116
+ Length max = UnitMath . Max ( firstValue , secondValue ) ;
117
+
118
+ Assert . Equal ( 1 , max . Value ) ;
119
+ Assert . Equal ( LengthUnit . Meter , max . Unit ) ;
120
+ }
121
+
64
122
[ Fact ]
65
123
public void MaxOfDifferentUnitsThrowsException ( )
66
124
{
@@ -69,6 +127,14 @@ public void MaxOfDifferentUnitsThrowsException()
69
127
Assert . Throws < ArgumentException > ( ( ) => units . Max ( LengthUnit . Centimeter ) ) ;
70
128
}
71
129
130
+ [ Fact ]
131
+ public void MaxOfLengthsWithNullValueThrowsException ( )
132
+ {
133
+ var units = new IQuantity [ ] { Length . FromMeters ( 1 ) , null } ;
134
+
135
+ Assert . Throws < NullReferenceException > ( ( ) => units . Max ( LengthUnit . Centimeter ) ) ;
136
+ }
137
+
72
138
[ Fact ]
73
139
public void MaxOfEmptySourceThrowsException ( )
74
140
{
@@ -115,6 +181,18 @@ public void MaxOfLengthsWithSelectorCalculatesCorrectly()
115
181
Assert . Equal ( LengthUnit . Centimeter , max . Unit ) ;
116
182
}
117
183
184
+ [ Fact ]
185
+ public void MinOfTwoLengthsReturnsTheSmallestValue ( )
186
+ {
187
+ var firstValue = Length . FromMeters ( 1 ) ;
188
+ var secondValue = Length . FromCentimeters ( 50 ) ;
189
+
190
+ Length min = UnitMath . Min ( firstValue , secondValue ) ;
191
+
192
+ Assert . Equal ( 50 , min . Value ) ;
193
+ Assert . Equal ( LengthUnit . Centimeter , min . Unit ) ;
194
+ }
195
+
118
196
[ Fact ]
119
197
public void MinOfDifferentUnitsThrowsException ( )
120
198
{
@@ -123,6 +201,14 @@ public void MinOfDifferentUnitsThrowsException()
123
201
Assert . Throws < ArgumentException > ( ( ) => units . Min ( LengthUnit . Centimeter ) ) ;
124
202
}
125
203
204
+ [ Fact ]
205
+ public void MinOfLengthsWithNullValueThrowsException ( )
206
+ {
207
+ var units = new IQuantity [ ] { Length . FromMeters ( 1 ) , null } ;
208
+
209
+ Assert . Throws < NullReferenceException > ( ( ) => units . Min ( LengthUnit . Centimeter ) ) ;
210
+ }
211
+
126
212
[ Fact ]
127
213
public void MinOfEmptySourceThrowsException ( )
128
214
{
@@ -177,6 +263,14 @@ public void SumOfDifferentUnitsThrowsException()
177
263
Assert . Throws < ArgumentException > ( ( ) => units . Sum ( LengthUnit . Centimeter ) ) ;
178
264
}
179
265
266
+ [ Fact ]
267
+ public void SumOfLengthsWithNullValueThrowsException ( )
268
+ {
269
+ var units = new IQuantity [ ] { Length . FromMeters ( 1 ) , null } ;
270
+
271
+ Assert . Throws < NullReferenceException > ( ( ) => units . Sum ( LengthUnit . Centimeter ) ) ;
272
+ }
273
+
180
274
[ Fact ]
181
275
public void SumOfEmptySourceReturnsZero ( )
182
276
{
0 commit comments