-
Notifications
You must be signed in to change notification settings - Fork 395
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
Changes from 22 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…
b8c6393
From YektaMirkan/Units - Added enum of pressure reference - by gratestas
b327ad5
From YektaMirkan/Units - Added pressure wrapper for pressure referenc…
ee072e9
Broke out tests into individual assertions. Corrected test values in …
27b06e3
Removed line in ReferencePressure.As that was causing sign errors and…
c7fcabc
Corrected issues with pressures less than absolute zero
e69383f
Updated nuget packages
77137f8
Improved code coverage and corrected exception handling
71708c8
Cleaned up unnecessary coverage file
b9d5045
Relocated the code created by gratestas from GeneratedCode to CustomCode
db74663
Old habits... rolling back NuGet packages to originals
82d65db
Renamed unit tests
ca68e3b
Sorted unit tests in PressureTests
a6a4b49
Refactored Pressure wrapper per review comments
b4fe2dd
Removed Pressure Reference property from Pressure.g generated code
aba8c9b
Added XML comments to Pressure.Wrapper
cf9e591
Added additional constructor overload for a user-specified atmospheri…
50a8c67
Merge branch 'master' of https://github.com/angularsen/unitsnet
28842bf
Updated target framework to latest minor in all projects
ffa1d05
Renamed files added to CustomCode, ran ReSharper rules on solution to…
ca7caf1
Revert "Renamed files added to CustomCode, ran ReSharper rules on sol…
2f7ef1e
Renamed .cs file and moved static methods.
afbc3b4
Changes based on change request.
9db829d
Changed IReadonlyList back to List, as it is not compatible with .NET…
04e9534
Changed References from list to array to minimize user modification.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.