public void BothTimersShouldFreezeWhenOneReachesZero() { var gameTime = GetRandomTimeMilliseconds(100, 200); var clock = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(40, 60); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.PressButton(Player.ONE); Thread.Sleep(gameTime + _errorMargin); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime, clock.GetRemainingTime(Player.ONE))); Assert.AreEqual(TimeSpan.Zero, clock.GetRemainingTime(Player.TWO)); }
public void PressingTheSameButtonTwiceInARowHasNoEffect() { var gameTime = GetRandomTimeMinutes(1, 30); var clock = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(100, 200); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); var playerOneTimeLeft = clock.GetRemainingTime(Player.ONE); Assert.AreEqual(gameTime, clock.GetRemainingTime(Player.TWO)); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime - waitTime, playerOneTimeLeft)); }
public void ClockCanBeReset() { var gameTime = GetRandomTimeMinutes(1, 30); var clock = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(100, 200); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.PressButton(Player.ONE); Thread.Sleep(waitTime); clock.Reset(); Thread.Sleep(waitTime); Assert.AreEqual(gameTime, clock.GetRemainingTime(Player.ONE)); Assert.AreEqual(gameTime, clock.GetRemainingTime(Player.TWO)); }
public void PressingPlayerButtonsShouldHaveNoEffectAfterTimeUp() { var gameTime = GetRandomTimeMilliseconds(100, 200); var clock = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(40, 60); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.PressButton(Player.ONE); Thread.Sleep(gameTime + _errorMargin); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.PressButton(Player.ONE); Thread.Sleep(waitTime); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime, clock.GetRemainingTime(Player.ONE))); Assert.AreEqual(TimeSpan.Zero, clock.GetRemainingTime(Player.TWO)); }
public void ClockShouldCountdownAsExpected() { var gameTime = GetRandomTimeMinutes(1, 30); var clock = new NoDelayChessClock(gameTime); var playerOneWaitTime = GetRandomTimeMilliseconds(100, 200); var playerTwoWaitTime = GetRandomTimeMilliseconds(100, 200); clock.PressButton(Player.TWO); Thread.Sleep(playerOneWaitTime); clock.PressButton(Player.ONE); var playerOneTimeLeft = clock.GetRemainingTime(Player.ONE); Thread.Sleep(playerTwoWaitTime); clock.PressButton(Player.TWO); var playerTwoTimeLeft = clock.GetRemainingTime(Player.TWO); Assert.IsTrue(IsWithinErrorMargin(gameTime - playerOneWaitTime, playerOneTimeLeft)); Assert.IsTrue(IsWithinErrorMargin(gameTime - playerTwoWaitTime, playerTwoTimeLeft)); }
public void EitherPlayerCanStartTheClock() { var gameTime = GetRandomTimeMinutes(1, 30); var clock1 = new NoDelayChessClock(gameTime); var clock2 = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(100, 200); clock1.PressButton(Player.ONE); clock2.PressButton(Player.TWO); Thread.Sleep(waitTime); var playerOneTimeLeft = clock2.GetRemainingTime(Player.ONE); var playerTwoTimeLeft = clock1.GetRemainingTime(Player.TWO); Assert.AreEqual(gameTime, clock1.GetRemainingTime(Player.ONE)); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime, playerTwoTimeLeft)); Assert.AreEqual(gameTime, clock2.GetRemainingTime(Player.TWO)); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime, playerOneTimeLeft)); }
public void ClockCanBePausedAndResumed() { var gameTime = GetRandomTimeMinutes(4, 5); var clock = new NoDelayChessClock(gameTime); var waitTime = GetRandomTimeMilliseconds(100, 200); clock.PressButton(Player.TWO); Thread.Sleep(waitTime); clock.Pause(); var playerOnePausedTime = clock.GetRemainingTime(Player.ONE); var playerTwoPausedTime = clock.GetRemainingTime(Player.TWO); clock.Resume(); Thread.Sleep(waitTime); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime, playerOnePausedTime)); Assert.IsTrue(IsWithinErrorMargin(gameTime - waitTime - waitTime, clock.GetRemainingTime(Player.ONE))); Assert.AreEqual(gameTime, playerTwoPausedTime); Assert.AreEqual(gameTime, clock.GetRemainingTime(Player.TWO)); }