Skip to content

Commit cf1b16c

Browse files
vKaras1337angularsen
authored andcommitted
operator overloads for ElectricCurrentGradient and time to ElectricCurrent
and PressureChangeRate and Time to Pressure
1 parent 7d772b3 commit cf1b16c

File tree

8 files changed

+137
-1
lines changed

8 files changed

+137
-1
lines changed

UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
using System;
2525

26+
using Xunit;
27+
2628
namespace UnitsNet.Tests.CustomCode
2729
{
2830
public class ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase
@@ -36,5 +38,19 @@ public class ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase
3638
protected override double AmperesPerMinuteInOneAmperePerSecond => 60;
3739
protected override double MilliamperesPerMinuteInOneAmperePerSecond => 6e4;
3840
protected override double MilliamperesPerSecondInOneAmperePerSecond => 1e3;
41+
42+
[Fact]
43+
public void ElectricCurrentGradientTimesDurationEqualsElectricCurrent()
44+
{
45+
ElectricCurrent electricCurrent = ElectricCurrentGradient.FromAmperesPerSecond(10) * Duration.FromSeconds(2);
46+
Assert.Equal(ElectricCurrent.FromAmperes(20) ,electricCurrent);
47+
}
48+
49+
[Fact]
50+
public void ElectricCurrentGradientTimesTimeSpanEqualsElectricCurrent()
51+
{
52+
ElectricCurrent electricCurrent = ElectricCurrentGradient.FromAmperesPerSecond(10) * TimeSpan.FromSeconds(2);
53+
Assert.Equal(ElectricCurrent.FromAmperes(20), electricCurrent);
54+
}
3955
}
4056
}

UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using System;
5+
46
using Xunit;
57

68
namespace UnitsNet.Tests
@@ -52,5 +54,19 @@ public void ElectricCurrentMultipliedByDurationEqualsElectricCharge()
5254
ElectricCharge ah = ElectricCurrent.FromAmperes(4) * Duration.FromHours(5);
5355
Assert.Equal(20, ah.AmpereHours);
5456
}
57+
58+
[Fact]
59+
public void ElectricCurrentDividedByDurationEqualsElectricCurrentGradient()
60+
{
61+
ElectricCurrentGradient electricCurrentGradient = ElectricCurrent.FromAmperes(10) / Duration.FromSeconds(2);
62+
Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(5), electricCurrentGradient);
63+
}
64+
65+
[Fact]
66+
public void ElectricCurrentDividedByTimeSpanEqualsElectricCurrentGradient()
67+
{
68+
ElectricCurrentGradient electricCurrentGradient = ElectricCurrent.FromAmperes(10) / TimeSpan.FromSeconds(2);
69+
Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(5), electricCurrentGradient);
70+
}
5571
}
5672
}

UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using System;
5+
6+
using Xunit;
7+
48
namespace UnitsNet.Tests
59
{
610
public class PressureChangeRateTests : PressureChangeRateTestsBase
711
{
812
protected override bool SupportsSIUnitSystem => false;
9-
protected override double AtmospheresPerSecondInOnePascalPerSecond => 9.8692*1E-6;
13+
protected override double AtmospheresPerSecondInOnePascalPerSecond => 9.8692 * 1E-6;
1014

1115
protected override double KilopascalsPerSecondInOnePascalPerSecond => 1e-3;
1216

@@ -41,5 +45,19 @@ public class PressureChangeRateTests : PressureChangeRateTestsBase
4145
protected override double MillibarsPerMinuteInOnePascalPerSecond => 0.6;
4246

4347
protected override double MillibarsPerSecondInOnePascalPerSecond => 1e-2;
48+
49+
[Fact]
50+
public void PressureChangeRateTimesDurationEqualsPressure()
51+
{
52+
Pressure pressure = PressureChangeRate.FromPascalsPerSecond(500) * Duration.FromSeconds(2);
53+
Assert.Equal(Pressure.FromPascals(1000), pressure);
54+
}
55+
56+
[Fact]
57+
public void PressureChangeRateTimesTimeSpanEqualsPressure()
58+
{
59+
Pressure pressure = PressureChangeRate.FromPascalsPerSecond(500) * TimeSpan.FromSeconds(2);
60+
Assert.Equal(Pressure.FromPascals(1000), pressure);
61+
}
4462
}
4563
}

UnitsNet.Tests/CustomCode/PressureTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,19 @@ public void PressureDividedByReciprocalAreaEqualsForce()
248248
Force force = Pressure.FromPascals(200) / ReciprocalArea.FromInverseSquareMeters(5);
249249
Assert.Equal(force, Force.FromNewtons(40));
250250
}
251+
252+
[Fact]
253+
public void PressureDividedByDurationEqualsPressureChangeRate()
254+
{
255+
PressureChangeRate pressureChangeRate = Pressure.FromPascals(500) / Duration.FromSeconds(2);
256+
Assert.Equal(PressureChangeRate.FromPascalsPerSecond(250), pressureChangeRate);
257+
}
258+
259+
[Fact]
260+
public void PressureDividedByTimeSpanEqualsPressurechangeRate()
261+
{
262+
PressureChangeRate pressureChangeRate = Pressure.FromPascals(50) / TimeSpan.FromSeconds(5);
263+
Assert.Equal(PressureChangeRate.FromPascalsPerSecond(10), pressureChangeRate);
264+
}
251265
}
252266
}

UnitsNet/CustomCode/Quantities/ElectricCurrent.extra.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using System;
5+
46
namespace UnitsNet
57
{
68
public partial struct ElectricCurrent
@@ -24,5 +26,17 @@ public partial struct ElectricCurrent
2426
{
2527
return ElectricCharge.FromAmpereHours(current.Amperes * time.Hours);
2628
}
29+
30+
/// <summary>Get <see cref="ElectricCurrentGradient"/> from <see cref="ElectricCurrent"/> divided by <see cref="Duration"/>.</summary>
31+
public static ElectricCurrentGradient operator /(ElectricCurrent current, Duration duration)
32+
{
33+
return ElectricCurrentGradient.FromAmperesPerSecond(current.Amperes / duration.Seconds);
34+
}
35+
36+
/// <summary>Get <see cref="ElectricCurrentGradient"/> from <see cref="ElectricCurrent"/> divided by <see cref="TimeSpan"/>.</summary>
37+
public static ElectricCurrentGradient operator /(ElectricCurrent current, TimeSpan timeSpan)
38+
{
39+
return ElectricCurrentGradient.FromAmperesPerSecond(current.Amperes / timeSpan.TotalSeconds);
40+
}
2741
}
2842
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 ElectricCurrentGradient
9+
{
10+
/// <summary>Get <see cref="ElectricCurrent"/> from <see cref="ElectricCurrentGradient"/> times <see cref="Duration"/>.</summary>
11+
public static ElectricCurrent operator *(ElectricCurrentGradient currentGradient, Duration duration)
12+
{
13+
return ElectricCurrent.FromAmperes(currentGradient.AmperesPerSecond * duration.Seconds);
14+
}
15+
16+
/// <summary>Get <see cref="ElectricCurrent"/> from <see cref="ElectricCurrentGradient"/> times <see cref="TimeSpan"/>.</summary>
17+
public static ElectricCurrent operator *(ElectricCurrentGradient currentGradient, TimeSpan timeSpan)
18+
{
19+
return ElectricCurrent.FromAmperes(currentGradient.AmperesPerSecond * timeSpan.TotalSeconds);
20+
}
21+
}
22+
}

UnitsNet/CustomCode/Quantities/Pressure.extra.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using System;
5+
46
namespace UnitsNet
57
{
68
public partial struct Pressure
@@ -40,5 +42,17 @@ public partial struct Pressure
4042
{
4143
return new Force(pressure.Pascals / reciprocalArea.InverseSquareMeters, UnitsNet.Units.ForceUnit.Newton);
4244
}
45+
46+
/// <summary>Get <see cref="PressureChangeRate"/> from <see cref="Pressure"/> divided by <see cref="TimeSpan"/> </summary>
47+
public static PressureChangeRate operator /(Pressure pressure, TimeSpan timeSpan)
48+
{
49+
return new PressureChangeRate(pressure.Pascals / timeSpan.TotalSeconds , UnitsNet.Units.PressureChangeRateUnit.PascalPerSecond);
50+
}
51+
52+
/// <summary>Get <see cref="PressureChangeRate"/> from <see cref="Pressure"/> divided by <see cref="Duration"/> </summary>
53+
public static PressureChangeRate operator /(Pressure pressure, Duration duration)
54+
{
55+
return new PressureChangeRate(pressure.Pascals / duration.Seconds, UnitsNet.Units.PressureChangeRateUnit.PascalPerSecond);
56+
}
4357
}
4458
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 PressureChangeRate
9+
{
10+
/// <summary>Get <see cref="Pressure"/> from <see cref="PressureChangeRate"/> times <see cref="TimeSpan"/> </summary>
11+
public static Pressure operator *(PressureChangeRate pressureChangeRate, TimeSpan timeSpan)
12+
{
13+
return new Pressure(pressureChangeRate.PascalsPerSecond * timeSpan.TotalSeconds , UnitsNet.Units.PressureUnit.Pascal);
14+
}
15+
16+
/// <summary>Get <see cref="Pressure"/> from <see cref="PressureChangeRate"/> times <see cref="Duration"/> </summary>
17+
public static Pressure operator *(PressureChangeRate pressureChangeRate, Duration duration)
18+
{
19+
return new Pressure(pressureChangeRate.PascalsPerSecond * duration.Seconds, UnitsNet.Units.PressureUnit.Pascal);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)