@@ -7,6 +7,44 @@ namespace UnitsNet.Tests
77{
88 public class UnitMathTests
99 {
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+
1048 [ Fact ]
1149 public void AverageOfDifferentUnitsThrowsException ( )
1250 {
@@ -23,6 +61,14 @@ public void AverageOfEmptySourceThrowsException()
2361 Assert . Throws < InvalidOperationException > ( ( ) => units . Average ( LengthUnit . Centimeter ) ) ;
2462 }
2563
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+
2672 [ Fact ]
2773 public void AverageOfLengthsCalculatesCorrectly ( )
2874 {
@@ -61,6 +107,18 @@ public void AverageOfLengthsWithSelectorCalculatesCorrectly()
61107 Assert . Equal ( LengthUnit . Centimeter , average . Unit ) ;
62108 }
63109
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+
64122 [ Fact ]
65123 public void MaxOfDifferentUnitsThrowsException ( )
66124 {
@@ -69,6 +127,14 @@ public void MaxOfDifferentUnitsThrowsException()
69127 Assert . Throws < ArgumentException > ( ( ) => units . Max ( LengthUnit . Centimeter ) ) ;
70128 }
71129
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+
72138 [ Fact ]
73139 public void MaxOfEmptySourceThrowsException ( )
74140 {
@@ -115,6 +181,18 @@ public void MaxOfLengthsWithSelectorCalculatesCorrectly()
115181 Assert . Equal ( LengthUnit . Centimeter , max . Unit ) ;
116182 }
117183
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+
118196 [ Fact ]
119197 public void MinOfDifferentUnitsThrowsException ( )
120198 {
@@ -123,6 +201,14 @@ public void MinOfDifferentUnitsThrowsException()
123201 Assert . Throws < ArgumentException > ( ( ) => units . Min ( LengthUnit . Centimeter ) ) ;
124202 }
125203
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+
126212 [ Fact ]
127213 public void MinOfEmptySourceThrowsException ( )
128214 {
@@ -177,6 +263,14 @@ public void SumOfDifferentUnitsThrowsException()
177263 Assert . Throws < ArgumentException > ( ( ) => units . Sum ( LengthUnit . Centimeter ) ) ;
178264 }
179265
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+
180274 [ Fact ]
181275 public void SumOfEmptySourceReturnsZero ( )
182276 {
0 commit comments