Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp)

/// <inheritdoc cref="IStopwatchFactory.GetTimestamp()" />
public long GetTimestamp()
=> _mockTimeSystem.TimeProvider.Read().Ticks;
=> _mockTimeSystem.TimeProvider.Read().Ticks * _tickPeriod;
Comment thread
vbreuss marked this conversation as resolved.
Resolved

/// <inheritdoc cref="IStopwatchFactory.New()" />
public IStopwatch New()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics;
using System.Threading;
using aweXpect.Chronology;
using System.Diagnostics;
using Testably.Abstractions.TimeSystem;

namespace Testably.Abstractions.Tests.TimeSystem;
Expand All @@ -10,7 +10,7 @@ public class StopwatchFactoryTests(TimeSystemTestData testData) : TimeSystemTest
[Test]
public async Task Frequency_ShouldReturnValueOfAtLeastTicksPerSecond()
{
var expectedMinimum = TimeSystem is RealTimeSystem
long expectedMinimum = TimeSystem is RealTimeSystem
? Stopwatch.Frequency
: TimeSpan.TicksPerSecond;
long frequency = TimeSystem.Stopwatch.Frequency;
Expand All @@ -29,7 +29,8 @@ public async Task GetElapsedTime_WithStartingAndEndingTimestamp_ShouldReturnValu
TimeSpan timestamp =
TimeSystem.Stopwatch.GetElapsedTime(startingTimestamp, endingTimestamp);

long actualStopwatchTicks = timestamp.Ticks * TimeSystem.Stopwatch.Frequency / TimeSpan.TicksPerSecond;
long actualStopwatchTicks =
timestamp.Ticks * TimeSystem.Stopwatch.Frequency / TimeSpan.TicksPerSecond;
await That(actualStopwatchTicks).IsEqualTo(expectedTicks);
}
#endif
Expand All @@ -45,7 +46,8 @@ public async Task GetElapsedTime_WithStartingTimestamp_ShouldReturnValue(long ex
TimeSpan timestamp =
TimeSystem.Stopwatch.GetElapsedTime(startingTimestamp);

long actualStopwatchTicks = timestamp.Ticks * TimeSystem.Stopwatch.Frequency / TimeSpan.TicksPerSecond;
long actualStopwatchTicks =
timestamp.Ticks * TimeSystem.Stopwatch.Frequency / TimeSpan.TicksPerSecond;
await That(actualStopwatchTicks).IsGreaterThanOrEqualTo(expectedTicks);
}
#endif
Expand All @@ -61,6 +63,20 @@ public async Task GetTimestamp_AfterDelay_ShouldBeDifferent()
await That(timestamp2).IsGreaterThan(timestamp1);
}

[Test]
public async Task GetTimestamp_DividedByFrequency_ShouldReturnSeconds()
{
Skip.If(TimeSystem is RealTimeSystem);

long timestamp1 = TimeSystem.Stopwatch.GetTimestamp();

await TimeSystem.Task.Delay(1.4.Seconds(), CancellationToken);

long timestamp2 = TimeSystem.Stopwatch.GetTimestamp();
await That((double)(timestamp2 - timestamp1) / TimeSystem.Stopwatch.Frequency)
.IsEqualTo(1.4).Within(0.2);
}

[Test]
public async Task GetTimestamp_ShouldReturnValue()
{
Expand Down
Loading