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
5 changes: 5 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/TennisGame.class
/TennisGameException.class
/TennisGameTest.class
/TennisGameTest2.class
/TennisGameActualTest.class
Binary file modified bin/TennisGame.class
Binary file not shown.
Binary file modified bin/TennisGameException.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 @@ -77,13 +77,13 @@ public String getScore() {
return "player2 wins";
}

if (player1Points >= 4 && player1Points == player2Points)
if (player1Points >= 3 && player1Points == player2Points)
return "deuce";

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 ;
Expand Down
74 changes: 69 additions & 5 deletions tests/TennisGameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;

import jdk.nashorn.internal.ir.annotations.Ignore;
import org.junit.Ignore;

public class TennisGameTest {

Expand All @@ -20,8 +20,9 @@ public class TennisGameTest {
// "player2 has advantage"
// "player1 wins"
// "player2 wins"
@Ignore
public void testTennisGame_Start() {

@Test
public void testTennisGame_Start_LoveLove() {
//Arrange
TennisGame game = new TennisGame();
//Act
Expand All @@ -31,7 +32,47 @@ public void testTennisGame_Start() {
}

@Test
public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameException {
public void testPlayerWins() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();

game.player2Scored();
game.player2Scored();

game.player1Scored();
game.player1Scored();
game.player1Scored();

//win
game.player1Scored();

//Act
String score = game.getScore() ;
// Assert
assertEquals("Win not happened", "player1 wins", score);
}

@Ignore
public void testFirstDeuce() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();

game.player1Scored();
game.player1Scored();
game.player1Scored();

game.player2Scored();
game.player2Scored();
game.player2Scored();

//Act
String score = game.getScore() ;
// Assert
assertEquals("Tie score incorrect", "deuce", score);
}

@Test
public void testRepeatedDeuce() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();

Expand All @@ -45,12 +86,34 @@ public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameE

game.player1Scored();
game.player2Scored();

//Act
String score = game.getScore() ;
// Assert
assertEquals("Tie score incorrect", "deuce", score);
}

@Test
public void testPlayerAdvantage() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();

game.player1Scored();
game.player1Scored();
game.player1Scored();

game.player2Scored();
game.player2Scored();
game.player2Scored();

game.player2Scored();

//Act
String score = game.getScore() ;
// Assert
assertEquals("Advantage is incorrect", "player2 has advantage", score);
}

@Test (expected = TennisGameException.class)
public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() throws TennisGameException {
//Arrange
Expand All @@ -63,5 +126,6 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr
//Act
// This statement should cause an exception
game.player1Scored();
}
}

}