You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to add Slovak localization, that requires a separate Formatter. I have written unit tests but when I run them, some of them are one-off.
Consider
[Theory]
[InlineData(1, "o hodinu")]
[InlineData(2, "o 2 hodiny")]
[InlineData(3, "o 3 hodiny")]
[InlineData(4, "o 4 hodiny")]
[InlineData(5, "o 5 hodín")]
[InlineData(6, "o 6 hodín")]
[InlineData(10, "o 10 hodín")]
public void NHoursFromNow(int number, string expected)
{
var humanize = DateTime.UtcNow.AddHours(number).Humanize();
Assert.Equal(expected, humanize);
}
When I run the tests, I get "o 9 hodín" for the last case testing "o 10 hodín". I guess the Humanize method got called with 9 instead of 10.
Am I missing something in writting the tests?
The text was updated successfully, but these errors were encountered:
This is an interesting issue which is hard to avoid. The problem is that sometimes some of the date/time related tests fail just because by the time the calculation is happening the CPU has ticked over which results into a value that's one unit larger or smaller than the expected value when you're checking the past and future dates respectively.
The only thing we could do to avoid this issue was to inject the base date in and to avoid the CPU ticking over by "freezing" the time. You can see this in DateTimeHumanizeTests here.
To fix this for your locale and to prevent it for all the other locales we will need to refactor the Verify logic out of the DateTimeHumanizeTests and apply it on all other locales in tests.
I am trying to add Slovak localization, that requires a separate Formatter. I have written unit tests but when I run them, some of them are one-off.
Consider
When I run the tests, I get "o 9 hodín" for the last case testing "o 10 hodín". I guess the Humanize method got called with 9 instead of 10.
Am I missing something in writting the tests?
The text was updated successfully, but these errors were encountered: