File tree Expand file tree Collapse file tree 6 files changed +62
-0
lines changed
UnitsNet.Tests/CustomCode
UnitsNet/CustomCode/Quantities Expand file tree Collapse file tree 6 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -39,5 +39,17 @@ public void ElectricChargeDividedByDurationEqualsElectricCurrent()
39
39
ElectricCurrent i = ElectricCharge . FromAmpereHours ( 20 ) / Duration . FromHours ( 4 ) ;
40
40
Assert . Equal ( 5 , i . Amperes ) ;
41
41
}
42
+
43
+ [ Theory ]
44
+ [ InlineData ( 1 , 1 , 1 ) ]
45
+ [ InlineData ( 0 , int . MaxValue , 0 ) ]
46
+ [ InlineData ( 10 , 2 , 20 ) ]
47
+ [ InlineData ( - 10 , 2 , - 20 ) ]
48
+ [ InlineData ( - 10 , - 2 , 20 ) ]
49
+ public void ElectricChargeMultipliedByElectricPotentialEqualsEnergy ( float current , float potential , float expected )
50
+ {
51
+ Energy j = ElectricCharge . FromCoulombs ( current ) * ElectricPotential . FromVolts ( potential ) ;
52
+ Assert . Equal ( expected , j . Joules ) ;
53
+ }
42
54
}
43
55
}
Original file line number Diff line number Diff line change @@ -50,5 +50,17 @@ public void ElectricPotentialMultipliedByElectricCurrentEqualsPower()
50
50
Power p = ElectricPotential . FromVolts ( 10 ) * ElectricCurrent . FromAmperes ( 2 ) ;
51
51
Assert . Equal ( 20 , p . Watts ) ;
52
52
}
53
+
54
+ [ Theory ]
55
+ [ InlineData ( 1 , 1 , 1 ) ]
56
+ [ InlineData ( 0 , int . MaxValue , 0 ) ]
57
+ [ InlineData ( 10 , 2 , 20 ) ]
58
+ [ InlineData ( - 10 , 2 , - 20 ) ]
59
+ [ InlineData ( - 10 , - 2 , 20 ) ]
60
+ public void ElectricPotentialMultipliedByElectricChargeEqualsEnergy ( float potential , float current , float expected )
61
+ {
62
+ Energy j = ElectricPotential . FromVolts ( potential ) * ElectricCharge . FromCoulombs ( current ) ;
63
+ Assert . Equal ( expected , j . Joules ) ;
64
+ }
53
65
}
54
66
}
Original file line number Diff line number Diff line change @@ -132,6 +132,20 @@ public void EnergyDividedByPowerEqualsDuration()
132
132
Assert . Equal ( 5 , d . Hours ) ;
133
133
}
134
134
135
+ [ Fact ]
136
+ public void EnergyDividedByElectricPotentialEqualsElectricCharge ( )
137
+ {
138
+ ElectricCharge c = Energy . FromJoules ( 20 ) / ElectricPotential . FromVolts ( 5 ) ;
139
+ Assert . Equal ( 4 , c . Coulombs ) ;
140
+ }
141
+
142
+ [ Fact ]
143
+ public void EnergyDividedByElectricChargeEqualsElectricPotential ( )
144
+ {
145
+ ElectricPotential v = Energy . FromJoules ( 20 ) / ElectricCharge . FromCoulombs ( 5 ) ;
146
+ Assert . Equal ( 4 , v . Volts ) ;
147
+ }
148
+
135
149
[ Fact ]
136
150
public void EnergyTimesFrequencyEqualsPower ( )
137
151
{
Original file line number Diff line number Diff line change @@ -16,5 +16,11 @@ public partial struct ElectricCharge
16
16
{
17
17
return Duration . FromHours ( charge . AmpereHours / current . Amperes ) ;
18
18
}
19
+
20
+ /// <summary>Get <see cref="Energy"/> from <see cref="ElectricCharge"/> times <see cref="ElectricPotential"/> .</summary>
21
+ public static Energy operator * ( ElectricCharge charge , ElectricPotential potential )
22
+ {
23
+ return Energy . FromJoules ( potential . Volts * charge . Coulombs ) ;
24
+ }
19
25
}
20
26
}
Original file line number Diff line number Diff line change @@ -39,5 +39,11 @@ public AmplitudeRatio ToAmplitudeRatio()
39
39
{
40
40
return Power . FromWatts ( potential . Volts * current . Amperes ) ;
41
41
}
42
+
43
+ /// <summary>Get <see cref="Energy"/> from <see cref="ElectricPotential"/> times <see cref="ElectricCharge"/>.</summary>
44
+ public static Energy operator * ( ElectricPotential potential , ElectricCharge charge )
45
+ {
46
+ return Energy . FromJoules ( potential . Volts * charge . Coulombs ) ;
47
+ }
42
48
}
43
49
}
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ public partial struct Energy
25
25
return Duration . FromSeconds ( energy . Joules / ( double ) power . Watts ) ;
26
26
}
27
27
28
+ /// <summary>Get <see cref="ElectricCharge"/> from <see cref="Energy"/> divided by <see cref="ElectricPotential"/>.</summary>
29
+ public static ElectricCharge operator / ( Energy energy , ElectricPotential potential )
30
+ {
31
+ return ElectricCharge . FromCoulombs ( energy . Joules / potential . Volts ) ;
32
+ }
33
+
34
+ /// <summary>Get <see cref="ElectricPotential"/> from <see cref="Energy"/> divided by <see cref="ElectricCharge"/>.</summary>
35
+ public static ElectricPotential operator / ( Energy energy , ElectricCharge current )
36
+ {
37
+ return ElectricPotential . FromVolts ( energy . Joules / current . Coulombs ) ;
38
+ }
39
+
28
40
/// <summary>Get <see cref="Power"/> from <see cref="Energy"/> times <see cref="Frequency"/>.</summary>
29
41
public static Power operator * ( Energy energy , Frequency frequency )
30
42
{
You can’t perform that action at this time.
0 commit comments