public string GetScore()
{
string score = "";
var tempScore = 0;
if (m_score1 == m_score2)
{
switch (m_score1)
{
case 0:
score = "Love-All";
break;
case 1:
score = "Fifteen-All";
break;
case 2:
score = "Thirty-All";
break;
default:
score = "Deuce";
break;
}
}
else if (m_score1 >= 4 || m_score2 >= 4)
{
var minusResult = m_score1 - m_score2;
if (minusResult == 1) score = "Advantage player1";
else if (minusResult == -1) score = "Advantage player2";
else if (minusResult >= 2) score = "Win for player1";
else score = "Win for player2";
}
else
{
for (var i = 1; i < 3; i++)
{
if (i == 1) tempScore = m_score1;
else { score += "-"; tempScore = m_score2; }
switch (tempScore)
{
case 0:
score += "Love";
break;
case 1:
score += "Fifteen";
break;
case 2:
score += "Thirty";
break;
case 3:
score += "Forty";
break;
}
}
}
return score;
}
public void PlayerOneWinsTwoGamesWithSecondGameGoingToAdvantage() { var game = new TennisGame1(new GameScore(player1Name, player2Name)); var pointsWon = new List <Point> { new Point(player1Name, "Fifteen-Love"), new Point(player1Name, "Thirty-Love"), new Point(player2Name, "Thirty-Fifteen"), new Point(player2Name, "Thirty-All"), new Point(player1Name, "Forty-Thirty"), new Point(player1Name, "Love-All"), new Point(player1Name, "Fifteen-Love"), new Point(player2Name, "Fifteen-All"), new Point(player1Name, "Thirty-Fifteen"), new Point(player2Name, "Thirty-All"), new Point(player2Name, "Thirty-Forty"), new Point(player1Name, "Deuce"), new Point(player1Name, "Advantage player1"), new Point(player2Name, "Deuce"), new Point(player1Name, "Advantage player1"), new Point(player1Name, "Love-All"), }; foreach (var pointWon in pointsWon) { game.WonPoint(pointWon.playerName); Assert.AreEqual(pointWon.score, game.GetScore()); } Assert.AreEqual(2, game.GetGamesWon(player1Name)); Assert.AreEqual(0, game.GetGamesWon(player2Name)); }