-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: added unit tests for new Double and Single floating-point types
- Loading branch information
Showing
21 changed files
with
804 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipedia.org/wiki/Celsius | ||
// https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Double; | ||
|
||
[Double(2, Minimum = -273.15d)] | ||
public partial record struct Celsius : ITemperature<Celsius> | ||
{ | ||
public static Celsius AbsoluteZero => new(-273.15d); | ||
|
||
public static Celsius WaterMeltingPoint => new(0d); | ||
|
||
public static Celsius WaterBoilingPoint => new(99.9839d); | ||
|
||
public static explicit operator Kelvin(Celsius value) => new(value + 273.15d); | ||
public static explicit operator Fahrenheit(Celsius value) => new((value * (9d / 5d)) + 32d); | ||
public static explicit operator Rankine(Celsius value) => new((value + 273.15d) * (9d / 5d)); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipedia.org/wiki/Celsius | ||
// https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Double; | ||
|
||
[Double(2, Minimum = -459.67d)] | ||
public partial record struct Fahrenheit : ITemperature<Fahrenheit> | ||
{ | ||
public static Fahrenheit AbsoluteZero => new(-459.67d); | ||
|
||
public static Fahrenheit WaterMeltingPoint => new(32d); | ||
|
||
public static Fahrenheit WaterBoilingPoint => new(211.97102d); | ||
|
||
public static explicit operator Celsius(Fahrenheit value) => new((value - 32d) * (5d / 9d)); | ||
public static explicit operator Kelvin(Fahrenheit value) => new((value + 459.67d) * (5d / 9d)); | ||
public static explicit operator Rankine(Fahrenheit value) => new(value + 459.67d); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipedia.org/wiki/Celsius | ||
// https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Double; | ||
|
||
[Double(2, Minimum = 0d)] | ||
public partial record struct Kelvin : ITemperature<Kelvin> | ||
{ | ||
public static Kelvin AbsoluteZero => new(0d); | ||
|
||
public static Kelvin WaterMeltingPoint => new(273.15d); | ||
|
||
public static Kelvin WaterBoilingPoint => new(373.1339d); | ||
|
||
public static explicit operator Celsius(Kelvin value) => new(value - 273.15d); | ||
public static explicit operator Fahrenheit(Kelvin value) => new((9d / 5d * value) - 459.67d); | ||
public static explicit operator Rankine(Kelvin value) => new(9d / 5d * value); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipedia.org/wiki/Celsius | ||
// https://en.wikipedia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Double; | ||
|
||
[Double(2, Minimum = 0d)] | ||
public partial record struct Rankine : ITemperature<Rankine> | ||
{ | ||
public static Rankine AbsoluteZero => new(0d); | ||
|
||
public static Rankine WaterMeltingPoint => new(491.67d); | ||
|
||
public static Rankine WaterBoilingPoint => new(671.64102d); | ||
|
||
public static explicit operator Celsius(Rankine value) => new((5d / 9d * value) - 273.15d); | ||
public static explicit operator Fahrenheit(Rankine value) => new(value - 459.67d); | ||
public static explicit operator Kelvin(Rankine value) => new(5d / 9d * value); | ||
} |
This file contains 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,10 @@ | ||
namespace Acme.TestLib2; | ||
|
||
public interface ITemperature<out T> where T : ITemperature<T> | ||
{ | ||
#if NET7_0_OR_GREATER | ||
static abstract T AbsoluteZero { get; } | ||
static abstract T WaterMeltingPoint { get; } | ||
static abstract T WaterBoilingPoint { get; } | ||
#endif | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipefia.org/wiki/Celsius | ||
// https://en.wikipefia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Single; | ||
|
||
[Single(2, Minimum = -273.15f)] | ||
public partial record struct Celsius : ITemperature<Celsius> | ||
{ | ||
public static Celsius AbsoluteZero => new(-273.15f); | ||
|
||
public static Celsius WaterMeltingPoint => new(0f); | ||
|
||
public static Celsius WaterBoilingPoint => new(99.9839f); | ||
|
||
public static explicit operator Kelvin(Celsius value) => new(value + 273.15f); | ||
public static explicit operator Fahrenheit(Celsius value) => new((value * (9f / 5f)) + 32f); | ||
public static explicit operator Rankine(Celsius value) => new((value + 273.15f) * (9f / 5f)); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipefia.org/wiki/Celsius | ||
// https://en.wikipefia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Single; | ||
|
||
[Single(2, Minimum = -459.67f)] | ||
public partial record struct Fahrenheit : ITemperature<Fahrenheit> | ||
{ | ||
public static Fahrenheit AbsoluteZero => new(-459.67f); | ||
|
||
public static Fahrenheit WaterMeltingPoint => new(32f); | ||
|
||
public static Fahrenheit WaterBoilingPoint => new(211.97102f); | ||
|
||
public static explicit operator Celsius(Fahrenheit value) => new((value - 32f) * (5f / 9f)); | ||
public static explicit operator Kelvin(Fahrenheit value) => new((value + 459.67f) * (5f / 9f)); | ||
public static explicit operator Rankine(Fahrenheit value) => new(value + 459.67f); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipefia.org/wiki/Celsius | ||
// https://en.wikipefia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Single; | ||
|
||
[Single(2, Minimum = 0f)] | ||
public partial record struct Kelvin : ITemperature<Kelvin> | ||
{ | ||
public static Kelvin AbsoluteZero => new(0f); | ||
|
||
public static Kelvin WaterMeltingPoint => new(273.15f); | ||
|
||
public static Kelvin WaterBoilingPoint => new(373.1339f); | ||
|
||
public static explicit operator Celsius(Kelvin value) => new(value - 273.15f); | ||
public static explicit operator Fahrenheit(Kelvin value) => new((9f / 5f * value) - 459.67f); | ||
public static explicit operator Rankine(Kelvin value) => new(9f / 5f * value); | ||
} |
This file contains 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,20 @@ | ||
using Primitively; | ||
|
||
// https://en.wikipefia.org/wiki/Celsius | ||
// https://en.wikipefia.org/wiki/Conversion_of_scales_of_temperature | ||
|
||
namespace Acme.TestLib2.Single; | ||
|
||
[Single(2, Minimum = 0f)] | ||
public partial record struct Rankine : ITemperature<Rankine> | ||
{ | ||
public static Rankine AbsoluteZero => new(0f); | ||
|
||
public static Rankine WaterMeltingPoint => new(491.67f); | ||
|
||
public static Rankine WaterBoilingPoint => new(671.64102f); | ||
|
||
public static explicit operator Celsius(Rankine value) => new((5f / 9f * value) - 273.15f); | ||
public static explicit operator Fahrenheit(Rankine value) => new(value - 459.67f); | ||
public static explicit operator Kelvin(Rankine value) => new(5f / 9f * value); | ||
} |
78 changes: 78 additions & 0 deletions
78
test/Primitively.IntegrationTests/NumericTests/Double/CelsiusTests.cs
This file contains 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,78 @@ | ||
using Acme.TestLib2.Double; | ||
|
||
namespace Primitively.IntegrationTests.NumericTests.Double; | ||
|
||
public class CelsiusTests | ||
{ | ||
[Fact] | ||
public void AbsoluteZero_In_Sut_Scale_Converts_To_AbsoluteZero_In_Other_Scales() | ||
{ | ||
// Assign | ||
var celsius = Celsius.AbsoluteZero; | ||
|
||
// Act | ||
var fahrenheit = (Fahrenheit)celsius; | ||
var kelvin = (Kelvin)celsius; | ||
var rankine = (Rankine)celsius; | ||
|
||
// Assert | ||
celsius.Should().BeEquivalentTo(Celsius.AbsoluteZero); | ||
fahrenheit.Should().BeEquivalentTo(Fahrenheit.AbsoluteZero); | ||
kelvin.Should().BeEquivalentTo(Kelvin.AbsoluteZero); | ||
rankine.Should().BeEquivalentTo(Rankine.AbsoluteZero); | ||
} | ||
|
||
[Fact] | ||
public void WaterMeltingPoint_In_Sut_Scale_Converts_To_WaterMeltingPoint_In_Other_Scales() | ||
{ | ||
// Assign | ||
var celsius = Celsius.WaterMeltingPoint; | ||
|
||
// Act | ||
var fahrenheit = (Fahrenheit)celsius; | ||
var kelvin = (Kelvin)celsius; | ||
var rankine = (Rankine)celsius; | ||
|
||
// Assert | ||
celsius.Should().BeEquivalentTo(Celsius.WaterMeltingPoint); | ||
fahrenheit.Should().BeEquivalentTo(Fahrenheit.WaterMeltingPoint); | ||
kelvin.Should().BeEquivalentTo(Kelvin.WaterMeltingPoint); | ||
rankine.Should().BeEquivalentTo(Rankine.WaterMeltingPoint); | ||
} | ||
|
||
[Fact] | ||
public void WaterBoilingPoint_In_Sut_Scale_Converts_To_WaterBoilingPoint_In_Other_Scales() | ||
{ | ||
// Assign | ||
var celsius = Celsius.WaterBoilingPoint; | ||
|
||
// Act | ||
var fahrenheit = (Fahrenheit)celsius; | ||
var kelvin = (Kelvin)celsius; | ||
var rankine = (Rankine)celsius; | ||
|
||
// Assert | ||
celsius.Should().BeEquivalentTo(Celsius.WaterBoilingPoint); | ||
fahrenheit.Should().BeEquivalentTo(Fahrenheit.WaterBoilingPoint); | ||
kelvin.Should().BeEquivalentTo(Kelvin.WaterBoilingPoint); | ||
rankine.Should().BeEquivalentTo(Rankine.WaterBoilingPoint); | ||
} | ||
|
||
[Fact] | ||
public void Minimum_Sut_Scale_Converts_To_Minimum_In_Other_Scales() | ||
{ | ||
// Assign | ||
var celsius = new Celsius(Celsius.Minimum); | ||
|
||
// Act | ||
double kelvin = (Kelvin)celsius; | ||
double fahrenheit = (Fahrenheit)celsius; | ||
double rankine = (Rankine)celsius; | ||
|
||
// Assert | ||
celsius.Should().BeEquivalentTo((Celsius)Celsius.Minimum); | ||
fahrenheit.Should().Be(Fahrenheit.Minimum); | ||
kelvin.Should().Be(Kelvin.Minimum); | ||
rankine.Should().Be(Rankine.Minimum); | ||
} | ||
} |
Oops, something went wrong.