Skip to content

Commit

Permalink
Ensure unit tests pass on machine with stopwatch frequency of 2,441,3…
Browse files Browse the repository at this point in the history
…67 after problem with earlier commit.
  • Loading branch information
cpsusie committed Nov 27, 2020
1 parent 5eb15b2 commit ade387f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion UnitTests/UnitTests/MonotonicStampTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public void PortableDurationConversionFailureTwoElaborationOne()
Assert.True(roundTripped.Ticks == timespanTicks);
}

[Fact]
public void TestPortableDurationConversionFailureCaseFour()
{
const long failingVal = -6_433_771_731_613_161_268;
TestPortableDurationDurationConversions(1, failingVal);
}

private IEnumerable<TimeSpan> GetNRandomTimespans(int numSpans)
{
if (numSpans < 0) throw new ArgumentOutOfRangeException(nameof(numSpans), numSpans, "Value may not be negative.");
Expand Down Expand Up @@ -267,7 +274,7 @@ private void AssertPortableDoubleCloseEnough(double portable, double notPortable
{
double epsilon = PortableDuration.TicksPerSecond == MonotonicStampFixture.StampContext.TicksPerSecond
? 0.25
: ((double) MonotonicStampFixture.StampContext.TicksPerSecond / PortableDuration.TicksPerSecond * 50.0) ;
: CalculateEpsilon(MonotonicStampFixture.StampContext.TicksPerSecond, PortableDuration.TicksPerSecond);//((double) MonotonicStampFixture.StampContext.TicksPerSecond / PortableDuration.TicksPerSecond * 75.0) ;
Assert.False(double.IsNaN(portable));
Assert.False(double.IsNaN(notPortable));
Assert.False(double.IsPositiveInfinity(portable) || double.IsNegativeInfinity(portable) || double.IsPositiveInfinity(notPortable) || double.IsNegativeInfinity(notPortable));
Expand All @@ -278,6 +285,13 @@ private void AssertPortableDoubleCloseEnough(double portable, double notPortable
Assert.False(true,
$"The absolute distance between {portable:N} and {notPortable:N} is {absVOfDiff:N} which is greater than {epsilon:N}.");
}

double CalculateEpsilon(double monotonicTicksPerSecond, double portableTicksPerSecond)
{
double greater = Math.Max(monotonicTicksPerSecond, portableTicksPerSecond);
double lesser = Math.Min(monotonicTicksPerSecond, portableTicksPerSecond);
return (1.0 - (lesser / greater));
}
}

private void AssertDoubleEqual(double expected, double actual, double epsilon = 0.5)
Expand Down

0 comments on commit ade387f

Please sign in to comment.