This commit is contained in:
@@ -65,17 +65,19 @@ namespace BritishHorseRacingApi.Tests
|
||||
}
|
||||
|
||||
[Theory()]
|
||||
[InlineData("3/5",1.6)]
|
||||
[InlineData("3/5", 1.6)]
|
||||
[InlineData("20/1",21)]
|
||||
[InlineData("", null)]
|
||||
[InlineData(" ", null)]
|
||||
[InlineData(null, null)]
|
||||
public void TestFractionOddsToDecimal(string value, decimal? expectedResult)
|
||||
public void TestFractionOddsToDecimal(string value, double? expectedResult)
|
||||
{
|
||||
//Arrange
|
||||
var decimalExpectedValue = (decimal?)expectedResult;
|
||||
//Act
|
||||
var result = DataConverterHelper.FractionOddsToDecimal(value);
|
||||
//Assert
|
||||
Assert.Equal(expectedResult, result);
|
||||
Assert.Equal(decimalExpectedValue, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ namespace BritishHorseRacingApi.Helpers
|
||||
var lossDifference = GetComponent(match, "lossDifference", 0d);
|
||||
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
|
||||
}
|
||||
private static Regex _ratioRegex = new Regex("(?'Numerator'[0-9]*)/(?'Denominator'[0-9]*)", RegexOptions.Compiled);
|
||||
private static Regex _ratioRegex = new Regex("(?'Numerator'[0-9]+)/(?'Denominator'[0-9]+)", RegexOptions.Compiled);
|
||||
public static decimal? FractionOddsToDecimal(string fraction)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(fraction))
|
||||
return null;
|
||||
|
||||
var match = _ratioRegex.Match(fraction);
|
||||
if (match.Groups.Count != 2)
|
||||
if (!match.Success)
|
||||
return null;
|
||||
|
||||
var numerator = Decimal.Parse(match.Groups["Numerator"].Value);
|
||||
|
||||
Reference in New Issue
Block a user