diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..0574187 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,5 @@ +/TennisGame.class +/TennisGameException.class +/TennisGameTest.class +/TennisGameTest2.class +/TennisGameActualTest.class diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7a..2318359 100644 Binary files a/bin/TennisGame.class and b/bin/TennisGame.class differ diff --git a/bin/TennisGameException.class b/bin/TennisGameException.class index d3bcf94..094639d 100644 Binary files a/bin/TennisGameException.class and b/bin/TennisGameException.class differ diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index b202db2..3b92bc2 100644 Binary files a/bin/TennisGameTest.class and b/bin/TennisGameTest.class differ diff --git a/src/TennisGame.java b/src/TennisGame.java index 327f284..ba9f578 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -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 ; diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..42ff3cf 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import jdk.nashorn.internal.ir.annotations.Ignore; +import org.junit.Ignore; public class TennisGameTest { @@ -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 @@ -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(); @@ -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 @@ -63,5 +126,6 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr //Act // This statement should cause an exception game.player1Scored(); - } + } + }