Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CoefficientOfThermalExpansion operators #1284

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions UnitsNet.Tests/CustomCode/CoefficientOfThermalExpansionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// 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.CustomCode
{
Expand All @@ -35,5 +34,25 @@ public class CoefficientOfThermalExpansionTests : CoefficientOfThermalExpansionT
protected override double InverseDegreeFahrenheitInOneInverseKelvin => 0.5555555555555556;

protected override double InverseKelvinInOneInverseKelvin => 1.0;

[Fact]
public void CoefficientOfThermalExpansionTimesTemperatureDelta()
{
double temperatureDeltaDegC = 2.0;
double ctePerDegC = 0.001;
CoefficientOfThermalExpansion cte = CoefficientOfThermalExpansion.FromInverseDegreeCelsius(ctePerDegC);
TemperatureDelta dT = TemperatureDelta.FromDegreesCelsius(temperatureDeltaDegC);
AssertEx.EqualTolerance(cte * dT, ctePerDegC * temperatureDeltaDegC, 1e-10);
}

[Fact]
public void TemperatureDeltaTimesCoefficientOfThermalExpansion()
{
double temperatureDeltaDegC = 2.0;
double ctePerDegC = 0.001;
CoefficientOfThermalExpansion cte = CoefficientOfThermalExpansion.FromInverseDegreeCelsius(ctePerDegC);
TemperatureDelta dT = TemperatureDelta.FromDegreesCelsius(temperatureDeltaDegC);
AssertEx.EqualTolerance(dT * cte, temperatureDeltaDegC * ctePerDegC, 1e-10);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace UnitsNet
{
public partial struct CoefficientOfThermalExpansion
{
/// <summary>Get a scalar from a <see cref="CoefficientOfThermalExpansion"/> multiplied by a <see cref="TemperatureDelta"/>.</summary>
public static double operator *(CoefficientOfThermalExpansion cte, TemperatureDelta temperatureDelta) => cte.InverseKelvin * temperatureDelta.Kelvins;
}
}
6 changes: 6 additions & 0 deletions UnitsNet/CustomCode/Quantities/TemperatureDelta.extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ public partial struct TemperatureDelta
{
return Energy.FromJoules(entropy.JoulesPerKelvin * temperatureDelta.Kelvins);
}

/// <summary>Get a scalar from a <see cref="TemperatureDelta"/> multiplied by a <see cref="CoefficientOfThermalExpansion"/>.</summary>
public static double operator *(TemperatureDelta temperatureDelta, CoefficientOfThermalExpansion cte)
{
return temperatureDelta.Kelvins * cte.InverseKelvin;
}
}
}