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