Skip to content

Commit

Permalink
operator overloads for ElectricCurrentGradient and time to ElectricCu…
Browse files Browse the repository at this point in the history
…rrent

and PressureChangeRate and Time to Pressure
  • Loading branch information
vKaras1337 authored and angularsen committed Jul 11, 2023
1 parent 7d772b3 commit cf1b16c
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 1 deletion.
16 changes: 16 additions & 0 deletions UnitsNet.Tests/CustomCode/ElectricCurrentGradientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

using System;

using Xunit;

namespace UnitsNet.Tests.CustomCode
{
public class ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase
Expand All @@ -36,5 +38,19 @@ public class ElectricCurrentGradientTests : ElectricCurrentGradientTestsBase
protected override double AmperesPerMinuteInOneAmperePerSecond => 60;
protected override double MilliamperesPerMinuteInOneAmperePerSecond => 6e4;
protected override double MilliamperesPerSecondInOneAmperePerSecond => 1e3;

[Fact]
public void ElectricCurrentGradientTimesDurationEqualsElectricCurrent()
{
ElectricCurrent electricCurrent = ElectricCurrentGradient.FromAmperesPerSecond(10) * Duration.FromSeconds(2);
Assert.Equal(ElectricCurrent.FromAmperes(20) ,electricCurrent);
}

[Fact]
public void ElectricCurrentGradientTimesTimeSpanEqualsElectricCurrent()
{
ElectricCurrent electricCurrent = ElectricCurrentGradient.FromAmperesPerSecond(10) * TimeSpan.FromSeconds(2);
Assert.Equal(ElectricCurrent.FromAmperes(20), electricCurrent);
}
}
}
16 changes: 16 additions & 0 deletions UnitsNet.Tests/CustomCode/ElectricCurrentTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

using Xunit;

namespace UnitsNet.Tests
Expand Down Expand Up @@ -52,5 +54,19 @@ public void ElectricCurrentMultipliedByDurationEqualsElectricCharge()
ElectricCharge ah = ElectricCurrent.FromAmperes(4) * Duration.FromHours(5);
Assert.Equal(20, ah.AmpereHours);
}

[Fact]
public void ElectricCurrentDividedByDurationEqualsElectricCurrentGradient()
{
ElectricCurrentGradient electricCurrentGradient = ElectricCurrent.FromAmperes(10) / Duration.FromSeconds(2);
Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(5), electricCurrentGradient);
}

[Fact]
public void ElectricCurrentDividedByTimeSpanEqualsElectricCurrentGradient()
{
ElectricCurrentGradient electricCurrentGradient = ElectricCurrent.FromAmperes(10) / TimeSpan.FromSeconds(2);
Assert.Equal(ElectricCurrentGradient.FromAmperesPerSecond(5), electricCurrentGradient);
}
}
}
20 changes: 19 additions & 1 deletion UnitsNet.Tests/CustomCode/PressureChangeRateTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

using Xunit;

namespace UnitsNet.Tests
{
public class PressureChangeRateTests : PressureChangeRateTestsBase
{
protected override bool SupportsSIUnitSystem => false;
protected override double AtmospheresPerSecondInOnePascalPerSecond => 9.8692*1E-6;
protected override double AtmospheresPerSecondInOnePascalPerSecond => 9.8692 * 1E-6;

protected override double KilopascalsPerSecondInOnePascalPerSecond => 1e-3;

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

protected override double MillibarsPerSecondInOnePascalPerSecond => 1e-2;

[Fact]
public void PressureChangeRateTimesDurationEqualsPressure()
{
Pressure pressure = PressureChangeRate.FromPascalsPerSecond(500) * Duration.FromSeconds(2);
Assert.Equal(Pressure.FromPascals(1000), pressure);
}

[Fact]
public void PressureChangeRateTimesTimeSpanEqualsPressure()
{
Pressure pressure = PressureChangeRate.FromPascalsPerSecond(500) * TimeSpan.FromSeconds(2);
Assert.Equal(Pressure.FromPascals(1000), pressure);
}
}
}
14 changes: 14 additions & 0 deletions UnitsNet.Tests/CustomCode/PressureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,19 @@ public void PressureDividedByReciprocalAreaEqualsForce()
Force force = Pressure.FromPascals(200) / ReciprocalArea.FromInverseSquareMeters(5);
Assert.Equal(force, Force.FromNewtons(40));
}

[Fact]
public void PressureDividedByDurationEqualsPressureChangeRate()
{
PressureChangeRate pressureChangeRate = Pressure.FromPascals(500) / Duration.FromSeconds(2);
Assert.Equal(PressureChangeRate.FromPascalsPerSecond(250), pressureChangeRate);
}

[Fact]
public void PressureDividedByTimeSpanEqualsPressurechangeRate()
{
PressureChangeRate pressureChangeRate = Pressure.FromPascals(50) / TimeSpan.FromSeconds(5);
Assert.Equal(PressureChangeRate.FromPascalsPerSecond(10), pressureChangeRate);
}
}
}
14 changes: 14 additions & 0 deletions UnitsNet/CustomCode/Quantities/ElectricCurrent.extra.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

namespace UnitsNet
{
public partial struct ElectricCurrent
Expand All @@ -24,5 +26,17 @@ public partial struct ElectricCurrent
{
return ElectricCharge.FromAmpereHours(current.Amperes * time.Hours);
}

/// <summary>Get <see cref="ElectricCurrentGradient"/> from <see cref="ElectricCurrent"/> divided by <see cref="Duration"/>.</summary>
public static ElectricCurrentGradient operator /(ElectricCurrent current, Duration duration)
{
return ElectricCurrentGradient.FromAmperesPerSecond(current.Amperes / duration.Seconds);
}

/// <summary>Get <see cref="ElectricCurrentGradient"/> from <see cref="ElectricCurrent"/> divided by <see cref="TimeSpan"/>.</summary>
public static ElectricCurrentGradient operator /(ElectricCurrent current, TimeSpan timeSpan)
{
return ElectricCurrentGradient.FromAmperesPerSecond(current.Amperes / timeSpan.TotalSeconds);
}
}
}
22 changes: 22 additions & 0 deletions UnitsNet/CustomCode/Quantities/ElectricCurrentGradient.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

namespace UnitsNet
{
public partial struct ElectricCurrentGradient
{
/// <summary>Get <see cref="ElectricCurrent"/> from <see cref="ElectricCurrentGradient"/> times <see cref="Duration"/>.</summary>
public static ElectricCurrent operator *(ElectricCurrentGradient currentGradient, Duration duration)
{
return ElectricCurrent.FromAmperes(currentGradient.AmperesPerSecond * duration.Seconds);
}

/// <summary>Get <see cref="ElectricCurrent"/> from <see cref="ElectricCurrentGradient"/> times <see cref="TimeSpan"/>.</summary>
public static ElectricCurrent operator *(ElectricCurrentGradient currentGradient, TimeSpan timeSpan)
{
return ElectricCurrent.FromAmperes(currentGradient.AmperesPerSecond * timeSpan.TotalSeconds);
}
}
}
14 changes: 14 additions & 0 deletions UnitsNet/CustomCode/Quantities/Pressure.extra.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

namespace UnitsNet
{
public partial struct Pressure
Expand Down Expand Up @@ -40,5 +42,17 @@ public partial struct Pressure
{
return new Force(pressure.Pascals / reciprocalArea.InverseSquareMeters, UnitsNet.Units.ForceUnit.Newton);
}

/// <summary>Get <see cref="PressureChangeRate"/> from <see cref="Pressure"/> divided by <see cref="TimeSpan"/> </summary>
public static PressureChangeRate operator /(Pressure pressure, TimeSpan timeSpan)
{
return new PressureChangeRate(pressure.Pascals / timeSpan.TotalSeconds , UnitsNet.Units.PressureChangeRateUnit.PascalPerSecond);
}

/// <summary>Get <see cref="PressureChangeRate"/> from <see cref="Pressure"/> divided by <see cref="Duration"/> </summary>
public static PressureChangeRate operator /(Pressure pressure, Duration duration)
{
return new PressureChangeRate(pressure.Pascals / duration.Seconds, UnitsNet.Units.PressureChangeRateUnit.PascalPerSecond);
}
}
}
22 changes: 22 additions & 0 deletions UnitsNet/CustomCode/Quantities/PressureChangeRate.extra.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed under MIT No Attribution, see LICENSE file at the root.
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.

using System;

namespace UnitsNet
{
public partial struct PressureChangeRate
{
/// <summary>Get <see cref="Pressure"/> from <see cref="PressureChangeRate"/> times <see cref="TimeSpan"/> </summary>
public static Pressure operator *(PressureChangeRate pressureChangeRate, TimeSpan timeSpan)
{
return new Pressure(pressureChangeRate.PascalsPerSecond * timeSpan.TotalSeconds , UnitsNet.Units.PressureUnit.Pascal);
}

/// <summary>Get <see cref="Pressure"/> from <see cref="PressureChangeRate"/> times <see cref="Duration"/> </summary>
public static Pressure operator *(PressureChangeRate pressureChangeRate, Duration duration)
{
return new Pressure(pressureChangeRate.PascalsPerSecond * duration.Seconds, UnitsNet.Units.PressureUnit.Pascal);
}
}
}

0 comments on commit cf1b16c

Please sign in to comment.