This commit is contained in:
@@ -36,7 +36,20 @@ namespace BritishHorseRacingApi.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory()]
|
[Theory()]
|
||||||
[InlineData("1m 1f 104y", 2084)]
|
[InlineData("1m 15.39s(+0.34s)", 340)]
|
||||||
|
[InlineData(null, null)]
|
||||||
|
[InlineData(" ", null)]
|
||||||
|
public void TestStopwatchStringDifferenceToMilliseconds(string time, double? expectedValue)
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
//Act
|
||||||
|
var totalMilliseconds = DataConverterHelper.StopwatchStringDifferenceToMilliseconds(time);
|
||||||
|
//Assert
|
||||||
|
Assert.Equal(totalMilliseconds, expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory()]
|
||||||
|
[InlineData("1m 1f 104y ", 2084)]
|
||||||
[InlineData("1f 104y", 324)]
|
[InlineData("1f 104y", 324)]
|
||||||
[InlineData("104y", 104)]
|
[InlineData("104y", 104)]
|
||||||
[InlineData("", null)]
|
[InlineData("", null)]
|
||||||
|
|||||||
@@ -58,10 +58,13 @@ namespace BritishHorseRacingApi.Helpers
|
|||||||
return (T)Convert.ChangeType(group.Value, typeof(T));
|
return (T)Convert.ChangeType(group.Value, typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int StopwatchStringDifferenceToMilliseconds(string timeDifferenceString)
|
public static int? StopwatchStringDifferenceToMilliseconds(string timeDifferenceString)
|
||||||
{
|
{
|
||||||
|
if (String.IsNullOrWhiteSpace(timeDifferenceString))
|
||||||
|
return null;
|
||||||
|
|
||||||
var match = _stopwatchTimeRegex.Match(timeDifferenceString);
|
var match = _stopwatchTimeRegex.Match(timeDifferenceString);
|
||||||
var lossDifference = GetComponent(match, "lossDifference", 0);
|
var lossDifference = GetComponent(match, "lossDifference", 0d);
|
||||||
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
|
return (int)TimeSpan.FromSeconds(lossDifference).TotalMilliseconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user