File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
UnitsNet.Tests/CustomCode
UnitsNet/CustomCode/Quantities Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1
1
// Licensed under MIT No Attribution, see LICENSE file at the root.
2
2
// Copyright 2013 Andreas Gullberg Larsen ([email protected] ). Maintained at https://github.com/angularsen/UnitsNet.
3
3
4
+ using System ;
4
5
using UnitsNet . Units ;
5
6
using Xunit ;
6
7
@@ -105,5 +106,19 @@ public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity()
105
106
Assert . Equal ( 2110.11170524 , inSI . Value ) ;
106
107
Assert . Equal ( EnergyUnit . Joule , inSI . Unit ) ;
107
108
}
109
+
110
+ [ Fact ]
111
+ public void EnergyDividedByTimeSpanEqualsPower ( )
112
+ {
113
+ Power p = Energy . FromWattHours ( 10 ) / TimeSpan . FromHours ( 2 ) ;
114
+ Assert . Equal ( 5 , p . Watts ) ;
115
+ }
116
+
117
+ [ Fact ]
118
+ public void EnergyDividedByDurationEqualsPower ( )
119
+ {
120
+ Power p = Energy . FromWattHours ( 20 ) / Duration . FromHours ( 5 ) ;
121
+ Assert . Equal ( 4 , p . Watts ) ;
122
+ }
108
123
}
109
124
}
Original file line number Diff line number Diff line change
1
+ // Licensed under MIT No Attribution, see LICENSE file at the root.
2
+ // Copyright 2013 Andreas Gullberg Larsen ([email protected] ). Maintained at https://github.com/angularsen/UnitsNet.
3
+
4
+ using System ;
5
+
6
+ namespace UnitsNet
7
+ {
8
+ public partial struct Energy
9
+ {
10
+ /// <summary>Get <see cref="Power"/> from <see cref="Energy"/> divided by <see cref="TimeSpan"/>.</summary>
11
+ public static Power operator / ( Energy energy , TimeSpan time )
12
+ {
13
+ return Power . FromWatts ( energy . Joules / time . TotalSeconds ) ;
14
+ }
15
+
16
+ /// <summary>Get <see cref="Power"/> from <see cref="Energy"/> divided by <see cref="Duration"/>.</summary>
17
+ public static Power operator / ( Energy energy , Duration duration )
18
+ {
19
+ return Power . FromWatts ( energy . Joules / duration . Seconds ) ;
20
+ }
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments