Skip to content

Commit

Permalink
Added power category with mechanical and metrical horse power
Browse files Browse the repository at this point in the history
  • Loading branch information
putridparrot committed Mar 2, 2023
1 parent aaa4554 commit 14c4f82
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
59 changes: 59 additions & 0 deletions PutridParrot.Units.Tests/PowerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// <auto-generated>
// This code was generated by the UnitCodeGenerator tool
//
// Changes to this file will be lost if the code is regenerated
// </auto-generated>

using NUnit.Framework;
using FsCheck;
using PropertyAttribute = FsCheck.NUnit.PropertyAttribute;

namespace PutridParrot.Units.Tests
{
public class MechanicalHorsePowerTests
{
[Property]
public void FromMechanicalHorsePowerToMetricHorsePowerAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Power.MechanicalHorsePower.ToMetricHorsePower(value);
var convertBack = Power.MetricHorsePower.ToMechanicalHorsePower(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(65.0971, 65.9999749)]
[TestCase(121.317, 122.9996)]
[TestCase(86.7962, 88.0)]
public void ConvertKnownMechanicalHorsePowerToMetricHorsePower(double input, double expectation)
{
var result = Power.MechanicalHorsePower.ToMetricHorsePower(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
public class MetricHorsePowerTests
{
[Property]
public void FromMetricHorsePowerToMechanicalHorsePowerAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Power.MetricHorsePower.ToMechanicalHorsePower(value);
var convertBack = Power.MechanicalHorsePower.ToMetricHorsePower(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(126.734, 125.0)]
[TestCase(91.2483, 90.0)]
[TestCase(425.825, 419.9997)]
public void ConvertKnownMetricHorsePowerToMechanicalHorsePower(double input, double expectation)
{
var result = Power.MetricHorsePower.ToMechanicalHorsePower(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
}
39 changes: 39 additions & 0 deletions PutridParrot.Units/Power.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <auto-generated>
// This code was generated by the UnitCodeGenerator tool
//
// Changes to this file will be lost if the code is regenerated
// </auto-generated>

namespace PutridParrot.Units
{
/// <summary>
/// Power conversion functions
/// </summary>
public static class Power
{
/// <summary>
/// Mechanical Horse Power conversion functions
/// </summary>
public static class MechanicalHorsePower
{
/// <summary>
/// Converts the supplied Mechanical Horse Power value to Metric Horse Power
/// </summary>
/// <param name="value">The Mechanical Horse Power input value</param>
/// <returns>The value in Metric Horse Power</returns>
public static double ToMetricHorsePower(double value) => value * 1.013869665424;
}
/// <summary>
/// Metric Horse Power conversion functions
/// </summary>
public static class MetricHorsePower
{
/// <summary>
/// Converts the supplied Metric Horse Power value to Mechanical Horse Power
/// </summary>
/// <param name="value">The Metric Horse Power input value</param>
/// <returns>The value in Mechanical Horse Power</returns>
public static double ToMechanicalHorsePower(double value) => value / 1.013869665424;
}
}
}
2 changes: 1 addition & 1 deletion PutridParrot.Units/PutridParrot.Units.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Company>PutridParrot</Company>
<Authors>Mark Timmings</Authors>
<Description>Unit conversion functions for C#</Description>
<Version>1.0.13</Version>
<Version>1.0.14</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/putridparrot/PutridParrot.Units.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ Each unit of measure then includes functions to convert to each for example, con
* Stones (stone)
* Tonnes (tonne)

### Power

* Mechanical Horse Power (hp)
* Metric Horse Power (ps)

### Pressure

* Atmospheres (atm)
Expand Down

0 comments on commit 14c4f82

Please sign in to comment.