public void IsValidScore_ValidScores_ReturnsTrue() { // Arrange List <int> validValues = new List <int> { 0, 1, 21, 25, 33, 42, 50, 57, 60 }; foreach (int item in validValues) { // Act bool result = Dart.IsValidScore(item); // Assert Assert.IsTrue(result, string.Format("{0} was expected to be valid", item)); } }
public void IsValidScore_InvalidScores_ReturnsFalse() { // Arrange List <int> invalidValues = new List <int> { -1, 23, 29, 35, 43, 52, 59, 61, 100 }; foreach (int item in invalidValues) { // Act bool result = Dart.IsValidScore(item); // Assert Assert.IsFalse(result, string.Format("{0} was expected to be invalid", item)); } }
/// <summary> /// Takes the points scored and updates the current score. Also determines the state of the turn based on result of the calculation. /// </summary> /// <param name="points">The points scored by the player.</param> /// <returns>True if the points are can be applied to the turn, otherwise false.</returns> public bool RecordPointsScored(int points) { // Make sure the state of the turn is appropriate for recording a score. // Make sure the points provided are valid for one dart. if (TurnState.InProgress != State || !Dart.IsValidScore(points)) { return(false); } // Update the current score. CurrentScore -= points; // Update last points scored LastPointsScored = points; // Update Dart's Points switch (DartsRemaining) { case 3: { // Is the first dart FirstDartPoints = points; break; } case 2: { // Is the second dart SecondDartPoints = points; break; } case 1: { // Is the third dart ThirdDartPoints = points; break; } } // Check for possible win. if (0 == CurrentScore) { DartsRemaining = 0; State = Dart.IsValidDouble(points) ? TurnState.Win : TurnState.Bust; return(true); } // Check for Bust scenarios. else if (1 == CurrentScore || 0 > CurrentScore) { DartsRemaining = 0; State = TurnState.Bust; return(true); } // Update the count of remaining darts. DartsRemaining--; // Check to see if the turn is done because all darts have been thrown. if (0 == DartsRemaining) { State = TurnState.Done; } return(true); }