public async Task GetCorrectedGravityAsync_ShouldReturnApproximate(decimal sg, decimal temp, decimal expected) { // Arrange var service = this.CreateService(); var specificGravity = SpecificGravity.FromGravity(sg); var temperature = temp; // Act var result = await service.GetCorrectedGravityAsync( specificGravity, temperature); // Assert result.Value.Should().BeApproximately(expected, 0.0005m); }
public SpecificGravity GetCorrectedGravity(SpecificGravity specificGravity, decimal temperature) { var calibrationTemperature = 20.0m; var farenheightTemperature = (temperature * 9 / 5) + 32; var farenheightCalibrationTemperature = (calibrationTemperature * 9 / 5) + 32; var correctedGravity = specificGravity.Value * (1.00130346m - (0.000134722124m * farenheightTemperature) + (0.00000204052596m * farenheightTemperature.ToPowerOf(2)) - (0.00000000232820948m * farenheightTemperature.ToPowerOf(3))) / (1.00130346m - (0.000134722124m * farenheightCalibrationTemperature) + (0.00000204052596m * farenheightCalibrationTemperature.ToPowerOf(2)) - (0.00000000232820948m * farenheightCalibrationTemperature.ToPowerOf(3))); return(SpecificGravity.FromGravity(correctedGravity)); }