File tree 6 files changed +56
-0
lines changed
UnitsNet/CustomCode/Quantities
UnitsNet.Tests/CustomCode
6 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -34,5 +34,12 @@ public void ElectricCurrentTimesElectricResistanceEqualsElectricPotential(float
34
34
ElectricPotential potential = ElectricCurrent . FromAmperes ( current ) * ElectricResistance . FromOhms ( resistance ) ;
35
35
Assert . Equal ( expected , potential . Volts ) ;
36
36
}
37
+
38
+ [ Fact ]
39
+ public void ElectricCurrentMultipliedByElectricPotentialEqualsPower ( )
40
+ {
41
+ Power p = ElectricCurrent . FromAmperes ( 2 ) * ElectricPotential . FromVolts ( 10 ) ;
42
+ Assert . Equal ( 20 , p . Watts ) ;
43
+ }
37
44
}
38
45
}
Original file line number Diff line number Diff line change @@ -40,5 +40,12 @@ public void ElectricPotentialDividedByElectricResistanceEqualsElectricCurrent(fl
40
40
ElectricCurrent current = ElectricPotential . FromVolts ( potential ) / ElectricResistance . FromOhms ( resistance ) ;
41
41
Assert . Equal ( expected , current . Amperes ) ;
42
42
}
43
+
44
+ [ Fact ]
45
+ public void ElectricPotentialMultipliedByElectricCurrentEqualsPower ( )
46
+ {
47
+ Power p = ElectricPotential . FromVolts ( 10 ) * ElectricCurrent . FromAmperes ( 2 ) ;
48
+ Assert . Equal ( 20 , p . Watts ) ;
49
+ }
43
50
}
44
51
}
Original file line number Diff line number Diff line change @@ -127,5 +127,19 @@ public void PowerDividedBySpecificEnergyEqualsMassFlow()
127
127
MassFlow massFlow = Power . FromWatts ( 15.0 ) / SpecificEnergy . FromJoulesPerKilogram ( 3 ) ;
128
128
Assert . Equal ( massFlow , MassFlow . FromKilogramsPerSecond ( 5 ) ) ;
129
129
}
130
+
131
+ [ Fact ]
132
+ public void PowerDividedByElectricCurrentEqualsElectricPotential ( )
133
+ {
134
+ ElectricPotential u = Power . FromWatts ( 10 ) / ElectricCurrent . FromAmperes ( 2 ) ;
135
+ Assert . Equal ( 5 , u . Volts ) ;
136
+ }
137
+
138
+ [ Fact ]
139
+ public void PowerDividedByElectricPotentialEqualsElectricCurrent ( )
140
+ {
141
+ ElectricCurrent i = Power . FromWatts ( 20 ) / ElectricPotential . FromVolts ( 5 ) ;
142
+ Assert . Equal ( 4 , i . Amperes ) ;
143
+ }
130
144
}
131
145
}
Original file line number Diff line number Diff line change @@ -11,5 +11,12 @@ public partial struct ElectricCurrent
11
11
{
12
12
return ElectricPotential . FromVolts ( resistance . Ohms * current . Amperes ) ;
13
13
}
14
+
15
+ /// <summary>Calculate <see cref="Power"/> from <see cref="ElectricPotential"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
16
+ /// <remarks>Electric power is defined as P = U * I.</remarks>
17
+ public static Power operator * ( ElectricCurrent current , ElectricPotential potential )
18
+ {
19
+ return Power . FromWatts ( potential . Volts * current . Amperes ) ;
20
+ }
14
21
}
15
22
}
Original file line number Diff line number Diff line change @@ -32,5 +32,12 @@ public AmplitudeRatio ToAmplitudeRatio()
32
32
{
33
33
return ElectricCurrent . FromAmperes ( potential . Volts / resistance . Ohms ) ;
34
34
}
35
+
36
+ /// <summary>Calculate <see cref="Power"/> from <see cref="ElectricPotential"/> multiplied by <see cref="ElectricCurrent"/>.</summary>
37
+ /// <remarks>Electric power is defined as P = U * I.</remarks>
38
+ public static Power operator * ( ElectricPotential potential , ElectricCurrent current )
39
+ {
40
+ return Power . FromWatts ( potential . Volts * current . Amperes ) ;
41
+ }
35
42
}
36
43
}
Original file line number Diff line number Diff line change @@ -92,5 +92,19 @@ public PowerRatio ToPowerRatio()
92
92
{
93
93
return Area . FromSquareMeters ( power . Watts / heatFlux . WattsPerSquareMeter ) ;
94
94
}
95
+
96
+ /// <summary>Calculate <see cref="ElectricCurrent"/> from <see cref="Power"/> divided by <see cref="ElectricPotential"/>.</summary>
97
+ /// <remarks>Electric power is defined as P = U * I, so I = P / U.</remarks>
98
+ public static ElectricCurrent operator / ( Power power , ElectricPotential potential )
99
+ {
100
+ return ElectricCurrent . FromAmperes ( power . Watts / potential . Volts ) ;
101
+ }
102
+
103
+ /// <summary>Calculate <see cref="ElectricPotential"/> from <see cref="Power"/> divided by <see cref="ElectricCurrent"/>.</summary>
104
+ /// <remarks>Electric power is defined as P = U * I, so I = P / U.</remarks>
105
+ public static ElectricPotential operator / ( Power power , ElectricCurrent current )
106
+ {
107
+ return ElectricPotential . FromVolts ( power . Watts / current . Amperes ) ;
108
+ }
95
109
}
96
110
}
You can’t perform that action at this time.
0 commit comments