Skip to content

Conversion between pressure measurement references #726

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

Merged
merged 25 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d805333
From YektaMirkan/Units - Added reference pressure property - by grate…
Dec 4, 2019
b8c6393
From YektaMirkan/Units - Added enum of pressure reference - by gratestas
Dec 4, 2019
b327ad5
From YektaMirkan/Units - Added pressure wrapper for pressure referenc…
Dec 4, 2019
ee072e9
Broke out tests into individual assertions. Corrected test values in …
Dec 4, 2019
27b06e3
Removed line in ReferencePressure.As that was causing sign errors and…
Dec 4, 2019
c7fcabc
Corrected issues with pressures less than absolute zero
Dec 5, 2019
e69383f
Updated nuget packages
Dec 6, 2019
77137f8
Improved code coverage and corrected exception handling
Dec 6, 2019
71708c8
Cleaned up unnecessary coverage file
Dec 6, 2019
b9d5045
Relocated the code created by gratestas from GeneratedCode to CustomCode
Dec 6, 2019
db74663
Old habits... rolling back NuGet packages to originals
Dec 9, 2019
82d65db
Renamed unit tests
Dec 9, 2019
ca68e3b
Sorted unit tests in PressureTests
Dec 9, 2019
a6a4b49
Refactored Pressure wrapper per review comments
Dec 9, 2019
b4fe2dd
Removed Pressure Reference property from Pressure.g generated code
Dec 9, 2019
aba8c9b
Added XML comments to Pressure.Wrapper
Dec 9, 2019
cf9e591
Added additional constructor overload for a user-specified atmospheri…
Dec 9, 2019
50a8c67
Merge branch 'master' of https://github.com/angularsen/unitsnet
Dec 11, 2019
28842bf
Updated target framework to latest minor in all projects
Dec 11, 2019
ffa1d05
Renamed files added to CustomCode, ran ReSharper rules on solution to…
Dec 11, 2019
ca7caf1
Revert "Renamed files added to CustomCode, ran ReSharper rules on sol…
Dec 11, 2019
2f7ef1e
Renamed .cs file and moved static methods.
Dec 11, 2019
afbc3b4
Changes based on change request.
Dec 11, 2019
9db829d
Changed IReadonlyList back to List, as it is not compatible with .NET…
Dec 11, 2019
04e9534
Changed References from list to array to minimize user modification.
Dec 11, 2019
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
1 change: 1 addition & 0 deletions CodeGen/CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<RootNamespace>UnitsNet.Serialization.JsonNet.CompatibilityTests</RootNamespace>
<LangVersion>7.3</LangVersion>
<LangVersion>latest</LangVersion>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<RootNamespace>UnitsNet.Serialization.JsonNet.Tests</RootNamespace>
<LangVersion>7.3</LangVersion>
<LangVersion>latest</LangVersion>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<!-- Assembly and msbuild properties -->
<PropertyGroup>
<AssemblyVersion>4.0.0.0</AssemblyVersion> <!-- Should reflect major part of Version -->
<LangVersion>7.3</LangVersion>
<LangVersion>latest</LangVersion>
<RootNamespace>UnitsNet.Serialization.JsonNet</RootNamespace>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
Expand Down
137 changes: 126 additions & 11 deletions UnitsNet.Tests/CustomCode/PressureTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +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 UnitsNet.CustomCode.Units;
using UnitsNet.CustomCode.Wrappers;
using Xunit;

namespace UnitsNet.Tests.CustomCode
{
public class PressureTests : PressureTestsBase
{
protected override double AtmospheresInOnePascal => 9.8692*1E-6;
protected override double AtmospheresInOnePascal => 9.8692 * 1E-6;

protected override double BarsInOnePascal => 1E-5;

Expand Down Expand Up @@ -47,15 +50,15 @@ public class PressureTests : PressureTestsBase

protected override double PoundsForcePerSquareInchInOnePascal => 1.450377377302092e-4;

protected override double TechnicalAtmospheresInOnePascal => 1.0197*1E-5;
protected override double TechnicalAtmospheresInOnePascal => 1.0197 * 1E-5;

protected override double TonnesForcePerSquareCentimeterInOnePascal => 1.019716212977928e-8;

protected override double TonnesForcePerSquareMeterInOnePascal => 1.019716212977928e-4;

protected override double TonnesForcePerSquareMillimeterInOnePascal => 1.019716212977928e-10;

protected override double TorrsInOnePascal => 7.5006*1E-3;
protected override double TorrsInOnePascal => 7.5006 * 1E-3;

protected override double CentibarsInOnePascal => 1e-3;

Expand Down Expand Up @@ -90,32 +93,144 @@ public class PressureTests : PressureTestsBase

protected override double MillipascalsInOnePascal => 1e3;

[Fact]
public void Absolute_WithAbsolutePressureReference_IsEqual()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Absolute);
AssertEx.EqualTolerance(3, refPressure.Absolute.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Absolute_WithDefaultPressureReference_IsEqual()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3));
AssertEx.EqualTolerance(3, refPressure.Absolute.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Absolute_WithGaugePressureReference_IsOneMore()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Gauge);
AssertEx.EqualTolerance(4, refPressure.Absolute.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Absolute_WithNegativeAbsolutePressureReference_ThrowsArgumentOutOfRangeException()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(-3), PressureReference.Absolute);
Assert.Throws<ArgumentOutOfRangeException>(() => refPressure.Absolute.Atmospheres);
}

[Fact]
public void Absolute_WithNegativeGaugePressureReference_ThrowsArgumentOutOfRangeException()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(-3), PressureReference.Gauge);
Assert.Throws<ArgumentOutOfRangeException>(() => refPressure.Absolute.Atmospheres);
}

[Fact]
public void Absolute_WithVacuumPressureReference_IsOneLessAtmosphereNegative()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(1), PressureReference.Vacuum);
AssertEx.EqualTolerance(0, refPressure.Absolute.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Absolute_WithVacuumPressureReference_ThrowsArgumentOutOfRangeException()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Vacuum);
Assert.Throws<ArgumentOutOfRangeException>(() => refPressure.Absolute.Atmospheres);
}

[Fact]
public void AreaTimesPressureEqualsForce()
{
Force force = Area.FromSquareMeters(3)*Pressure.FromPascals(20);
var force = Area.FromSquareMeters(3) * Pressure.FromPascals(20);
Assert.Equal(force, Force.FromNewtons(60));
}

[Fact]
public void PressureTimesAreaEqualsForce()
public void Gauge_WithDefaultPressureReference_IsOneLessAtmosphere()
{
Force force = Pressure.FromPascals(20)*Area.FromSquareMeters(3);
Assert.Equal(force, Force.FromNewtons(60));
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3));
AssertEx.EqualTolerance(2, refPressure.Gauge.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void PressureDividedBySpecificWeightEqualsLength()
public void Gauge_WithGaugePressureReference_IsEqual()
{
Length length = Pressure.FromPascals(20) / SpecificWeight.FromNewtonsPerCubicMeter(2);
Assert.Equal(Length.FromMeters(10), length);
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Gauge);
AssertEx.EqualTolerance(3, refPressure.Gauge.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Gauge_WithVacuumPressureReference_IsNegative()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(1), PressureReference.Vacuum);
AssertEx.EqualTolerance(-1, refPressure.Gauge.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Gauge_WithVacuumPressureReference_ThrowsArgumentOutOfRangeException()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Vacuum);
Assert.Throws<ArgumentOutOfRangeException>(() => refPressure.Gauge.Atmospheres);
}

[Fact]
public void PressureDividedByLengthEqualsSpecificWeight()
{
SpecificWeight specificWeight = Pressure.FromPascals(20) / Length.FromMeters(2);
var specificWeight = Pressure.FromPascals(20) / Length.FromMeters(2);
Assert.Equal(SpecificWeight.FromNewtonsPerCubicMeter(10), specificWeight);
}

[Fact]
public void PressureDividedBySpecificWeightEqualsLength()
{
var length = Pressure.FromPascals(20) / SpecificWeight.FromNewtonsPerCubicMeter(2);
Assert.Equal(Length.FromMeters(10), length);
}

[Fact]
public void PressureTimesAreaEqualsForce()
{
var force = Pressure.FromPascals(20) * Area.FromSquareMeters(3);
Assert.Equal(force, Force.FromNewtons(60));
}

// Pressure Measurement References
[Fact]
public void Reference_WithDefaultPressureReference_IsAbsolute()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3));
Equals(PressureReference.Absolute, refPressure.Reference);
}

[Fact]
public void ReferencesDoesNotContainUndefined()
{
Assert.DoesNotContain(PressureReference.Undefined, ReferencePressure.References);
}

[Fact]
public void Vacuum_WithDefaultPressureReference_IsOneLessAtmosphereNegative()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3));
AssertEx.EqualTolerance(-2, refPressure.Vacuum.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Vacuum_WithGaugePressureReference_IsNegative()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(3), PressureReference.Gauge);
AssertEx.EqualTolerance(-3, refPressure.Vacuum.Atmospheres, AtmospheresTolerance);
}

[Fact]
public void Vacuum_WithVacuumPressureReference_IsEqual()
{
var refPressure = new ReferencePressure(Pressure.FromAtmospheres(1), PressureReference.Vacuum);
AssertEx.EqualTolerance(1, refPressure.Vacuum.Atmospheres, AtmospheresTolerance);
}
}
}
1 change: 1 addition & 0 deletions UnitsNet.Tests/GeneratedCode/PressureTestsBase.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion UnitsNet.Tests/UnitsNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<RootNamespace>UnitsNet.Tests</RootNamespace>
<LangVersion>7.3</LangVersion>
<LangVersion>latest</LangVersion>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
34 changes: 34 additions & 0 deletions UnitsNet/CustomCode/Units/PressureReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
// Changes to this file will be lost when the code is regenerated.
// The build server regenerates the code before each build and a pre-build
// step will regenerate the code on each local build.
//
// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
//
// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities.
//
// </auto-generated>
//------------------------------------------------------------------------------

// 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.

// ReSharper disable once CheckNamespace
namespace UnitsNet.CustomCode.Units
{
// Disable missing XML comment warnings for the generated unit enums.
#pragma warning disable 1591

public enum PressureReference
{
Undefined = 0,
Absolute,
Gauge,
Vacuum,
}
#pragma warning restore 1591
}
Loading