public IEnumerator StartNewAndRestart() { var watch = UnityStopwatch.StartNew(); Assert.True(watch.IsRunning); yield return(null); var elapsedSinceStart = watch.Elapsed; Assert.True(elapsedSinceStart > TimeSpan.Zero); const int MaxAttempts = 5; // The comparison below could fail if we get very unlucky with when the thread gets preempted int attempt = 0; while (true) { watch.Restart(); Assert.True(watch.IsRunning); try { Assert.True(watch.Elapsed < elapsedSinceStart); } catch { if (++attempt < MaxAttempts) { continue; } throw; } break; } }
public IEnumerator StartNewAndReset() { var watch = UnityStopwatch.StartNew(); Assert.True(watch.IsRunning); watch.Start(); // should be no-op Assert.True(watch.IsRunning); yield return(null); Assert.True(watch.Elapsed > TimeSpan.Zero); watch.Reset(); Assert.False(watch.IsRunning); Assert.AreEqual(TimeSpan.Zero, watch.Elapsed); }