Created
August 28, 2020 08:12
-
-
Save snasphysicist/635cd90d10cdd4ef530fad655a5c30b1 to your computer and use it in GitHub Desktop.
Diffblue Cover Tennis Kata 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original: https://github.com/emilybache/Tennis-Refactoring-Kata/blob/master/java/src/main/java/TennisGame1.java | |
package com.example.tennis; | |
public class TennisScore { | |
public String announceScore(int m_score1, int m_score2) { | |
String score = ""; | |
int 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) { | |
int 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 (int 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment