This commit is contained in:
@@ -80,5 +80,24 @@ namespace BritishHorseRacingApi.Tests
|
|||||||
//Assert
|
//Assert
|
||||||
Assert.Equal(decimalExpectedValue, result);
|
Assert.Equal(decimalExpectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory()]
|
||||||
|
[InlineData("9st 4lbs", 58967.00662)]
|
||||||
|
[InlineData("11st 3lbs", 71214.00098)]
|
||||||
|
[InlineData("10lbs", 4535.92000)]
|
||||||
|
[InlineData("9st", 57152.63862)]
|
||||||
|
[InlineData("9st 0lbs", 57152.63862)]
|
||||||
|
[InlineData("", null)]
|
||||||
|
[InlineData(" ", null)]
|
||||||
|
[InlineData(null, null)]
|
||||||
|
public void TestWeightStringToGrams(string value, double? expectedResult)
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
var decimalExpectedValue = (decimal?)expectedResult;
|
||||||
|
//Act
|
||||||
|
var result = DataConverterHelper.WeightStringToGrams(value);
|
||||||
|
//Assert
|
||||||
|
Assert.Equal(decimalExpectedValue, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,5 +81,22 @@ namespace BritishHorseRacingApi.Helpers
|
|||||||
var denominator = Decimal.Parse(match.Groups["Denominator"].Value);
|
var denominator = Decimal.Parse(match.Groups["Denominator"].Value);
|
||||||
return (numerator / denominator) + 1;
|
return (numerator / denominator) + 1;
|
||||||
}
|
}
|
||||||
|
private static readonly Regex _weightStringRegex = new Regex("((?'stone'[0-9]+)?st)? ?((?'pounds'[0-9]+)lbs)?", RegexOptions.Compiled);
|
||||||
|
public static decimal? WeightStringToGrams(string value)
|
||||||
|
{
|
||||||
|
if (String.IsNullOrWhiteSpace(value))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var result = _weightStringRegex.Match(value);
|
||||||
|
|
||||||
|
var stoneGroup = result.Groups["stone"];
|
||||||
|
var stone = stoneGroup.Success ? Decimal.Parse(stoneGroup.Value) : 0;
|
||||||
|
|
||||||
|
var poundsGroup = result.Groups["pounds"];
|
||||||
|
var pounds = poundsGroup.Success ? Decimal.Parse(poundsGroup.Value) : 0;
|
||||||
|
|
||||||
|
var grams = (stone * 6350.29318m) + (pounds * 453.592m);
|
||||||
|
return grams;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,5 +139,6 @@ namespace BritishHorseRacingApi.Models
|
|||||||
|
|
||||||
public decimal? DecimalOdds() => DataConverterHelper.FractionOddsToDecimal(Odds);
|
public decimal? DecimalOdds() => DataConverterHelper.FractionOddsToDecimal(Odds);
|
||||||
public string RacehorseNameWithoutCountry => RacehorseName.Split('(')[0].Trim();
|
public string RacehorseNameWithoutCountry => RacehorseName.Split('(')[0].Trim();
|
||||||
|
public decimal? WeightInGrams => DataConverterHelper.WeightStringToGrams(WeightText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user