Skip to content

Commit

Permalink
Add Temp/Reaumur conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
putridparrot committed Jan 27, 2024
1 parent 14c4f82 commit 06620fa
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 1 deletion.
163 changes: 163 additions & 0 deletions PutridParrot.Units.Tests/TemperatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ public void ConvertKnownCelsiusToRankine(double input, double expectation)
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromCelsiusToReaumurAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Celsius.ToReaumur(value);
var convertBack = Temperature.Reaumur.ToCelsius(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(123.0, 98.4)]
[TestCase(15.67, 12.536)]
[TestCase(87.0, 69.6)]
public void ConvertKnownCelsiusToReaumur(double input, double expectation)
{
var result = Temperature.Celsius.ToReaumur(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
public class FahrenheitTests
{
Expand Down Expand Up @@ -135,6 +155,26 @@ public void ConvertKnownFahrenheitToRankine(double input, double expectation)
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromFahrenheitToReaumurAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Fahrenheit.ToReaumur(value);
var convertBack = Temperature.Reaumur.ToFahrenheit(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(67.0, 15.555555556)]
[TestCase(1.6, -13.511111111)]
[TestCase(900.0, 385.77777778)]
public void ConvertKnownFahrenheitToReaumur(double input, double expectation)
{
var result = Temperature.Fahrenheit.ToReaumur(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
public class KelvinTests
{
Expand Down Expand Up @@ -198,6 +238,26 @@ public void ConvertKnownKelvinToRankine(double input, double expectation)
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromKelvinToReaumurAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Kelvin.ToReaumur(value);
var convertBack = Temperature.Reaumur.ToKelvin(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(900.0, 501.48)]
[TestCase(1.3, -217.48)]
[TestCase(60.0, -170.52)]
public void ConvertKnownKelvinToReaumur(double input, double expectation)
{
var result = Temperature.Kelvin.ToReaumur(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
public class RankineTests
{
Expand Down Expand Up @@ -261,5 +321,108 @@ public void ConvertKnownRankineToKelvin(double input, double expectation)
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromRankineToReaumurAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Rankine.ToReaumur(value);
var convertBack = Temperature.Reaumur.ToRankine(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(900.0, 181.48)]
[TestCase(34.9, -203.00888889)]
[TestCase(0.7, -218.20888889)]
public void ConvertKnownRankineToReaumur(double input, double expectation)
{
var result = Temperature.Rankine.ToReaumur(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
public class ReaumurTests
{
[Property]
public void FromReaumurToKelvinAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Reaumur.ToKelvin(value);
var convertBack = Temperature.Kelvin.ToReaumur(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(128.0, 433.15)]
[TestCase(7.4, 282.4)]
[TestCase(1.5, 275.025)]
public void ConvertKnownReaumurToKelvin(double input, double expectation)
{
var result = Temperature.Reaumur.ToKelvin(input);
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromReaumurToCelsiusAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Reaumur.ToCelsius(value);
var convertBack = Temperature.Celsius.ToReaumur(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(1.5, 1.875)]
[TestCase(23.9, 29.875)]
[TestCase(0.3, 0.375)]
public void ConvertKnownReaumurToCelsius(double input, double expectation)
{
var result = Temperature.Reaumur.ToCelsius(input);
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromReaumurToFahrenheitAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Reaumur.ToFahrenheit(value);
var convertBack = Temperature.Fahrenheit.ToReaumur(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(0.3, 32.675)]
[TestCase(87.0, 227.75)]
[TestCase(34.1, 108.725)]
public void ConvertKnownReaumurToFahrenheit(double input, double expectation)
{
var result = Temperature.Reaumur.ToFahrenheit(input);
Assert.AreEqual(expectation, result, 0.01);
}

[Property]
public void FromReaumurToRankineAndBack()
{
Prop.ForAll<int>(value =>
{
var convertTo = Temperature.Reaumur.ToRankine(value);
var convertBack = Temperature.Rankine.ToReaumur(convertTo);
return Is.EqualTo(convertBack).Within(0.01).ApplyTo(value).IsSuccess;
}).QuickCheckThrowOnFailure();
}

[TestCase(34.1, 568.395)]
[TestCase(10.6, 515.52)]
[TestCase(1.9, 495.945)]
public void ConvertKnownReaumurToRankine(double input, double expectation)
{
var result = Temperature.Reaumur.ToRankine(input);
Assert.AreEqual(expectation, result, 0.01);
}

}
}
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.14</Version>
<Version>1.0.15</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/putridparrot/PutridParrot.Units.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
54 changes: 54 additions & 0 deletions PutridParrot.Units/Temperature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public static class Celsius
/// <param name="value">The Celsius input value</param>
/// <returns>The value in Rankine</returns>
public static double ToRankine(double value) => value * 9.0/5.0 + 491.67;
/// <summary>
/// Converts the supplied Celsius value to Reaumur
/// </summary>
/// <param name="value">The Celsius input value</param>
/// <returns>The value in Reaumur</returns>
public static double ToReaumur(double value) => value / 1.25;
}
/// <summary>
/// Fahrenheit conversion functions
Expand All @@ -58,6 +64,12 @@ public static class Fahrenheit
/// <param name="value">The Fahrenheit input value</param>
/// <returns>The value in Rankine</returns>
public static double ToRankine(double value) => value + 459.67;
/// <summary>
/// Converts the supplied Fahrenheit value to Reaumur
/// </summary>
/// <param name="value">The Fahrenheit input value</param>
/// <returns>The value in Reaumur</returns>
public static double ToReaumur(double value) => (value - 32.0) / 2.25;
}
/// <summary>
/// Kelvin conversion functions
Expand All @@ -82,6 +94,12 @@ public static class Kelvin
/// <param name="value">The Kelvin input value</param>
/// <returns>The value in Rankine</returns>
public static double ToRankine(double value) => value * 1.8;
/// <summary>
/// Converts the supplied Kelvin value to Reaumur
/// </summary>
/// <param name="value">The Kelvin input value</param>
/// <returns>The value in Reaumur</returns>
public static double ToReaumur(double value) => (value - 273.15) / 1.25;
}
/// <summary>
/// Rankine conversion functions
Expand All @@ -106,6 +124,42 @@ public static class Rankine
/// <param name="value">The Rankine input value</param>
/// <returns>The value in Kelvin</returns>
public static double ToKelvin(double value) => value / 1.8;
/// <summary>
/// Converts the supplied Rankine value to Reaumur
/// </summary>
/// <param name="value">The Rankine input value</param>
/// <returns>The value in Reaumur</returns>
public static double ToReaumur(double value) => (value - 491.67) / 2.25;
}
/// <summary>
/// Reaumur conversion functions
/// </summary>
public static class Reaumur
{
/// <summary>
/// Converts the supplied Reaumur value to Kelvin
/// </summary>
/// <param name="value">The Reaumur input value</param>
/// <returns>The value in Kelvin</returns>
public static double ToKelvin(double value) => value * 1.25 + 273.15;
/// <summary>
/// Converts the supplied Reaumur value to Celsius
/// </summary>
/// <param name="value">The Reaumur input value</param>
/// <returns>The value in Celsius</returns>
public static double ToCelsius(double value) => value * 1.25;
/// <summary>
/// Converts the supplied Reaumur value to Fahrenheit
/// </summary>
/// <param name="value">The Reaumur input value</param>
/// <returns>The value in Fahrenheit</returns>
public static double ToFahrenheit(double value) => value * 2.25 + 32.0;
/// <summary>
/// Converts the supplied Reaumur value to Rankine
/// </summary>
/// <param name="value">The Reaumur input value</param>
/// <returns>The value in Rankine</returns>
public static double ToRankine(double value) => value * 2.25 + 491.67;
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Each unit of measure then includes functions to convert to each for example, con
* Fahrenheit (F)
* Kelvin (K)
* Rankine (R)
* Reaumur (r)

### Time

Expand Down

0 comments on commit 06620fa

Please sign in to comment.