Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/TennisGame.class
Binary file not shown.
Binary file modified bin/TennisGameTest.class
Binary file not shown.
4 changes: 2 additions & 2 deletions src/TennisGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public String getScore() {
if (player1Points >= 4 && player1Points - player2Points == 1)
return "player1 has advantage";

if (player2Points > 4 && player2Points - player1Points == 1)
if (player2Points >= 4 && player2Points - player1Points == 1)
return "player2 has advantage";

return player2Score + " - " + player1Score ;
return player1Score + " - " + player2Score ;
}
}
50 changes: 49 additions & 1 deletion tests/TennisGameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,53 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr
//Act
// This statement should cause an exception
game.player1Scored();
}
}
@Test
public void testTennisGame_Player1LeadsBy15Points() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();
//Act
game.player1Scored();
//Act
String score = game.getScore();
// Assert
assertEquals("Player score incorrect", "15 - love", score);

}
@Test
public void testTennisGame_Player1HasAdvantage() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();
//Act
game.player1Scored();
game.player2Scored();
game.player1Scored();
game.player2Scored();
game.player1Scored();
game.player2Scored();
game.player1Scored();
//Act
String score = game.getScore();
// Assert
assertEquals("Player advantage incorrect", "player1 has advantage", score);
}

@Test
public void testTennisGame_Player2HasAdvantage() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();
//Act
game.player1Scored();
game.player2Scored();
game.player1Scored();
game.player2Scored();
game.player1Scored();
game.player2Scored();
game.player2Scored();
//Act
String score = game.getScore();
// Assert
assertEquals("Player advantage incorrect", "player2 has advantage", score);
}

}