diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7a..657207e 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..ed803cf 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..08e51b7 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..d197eee 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -21,14 +21,15 @@ else if (player2Points>=4 && player2Points-player1Points>=2) gameEnded = true; } - private String getScore(int points) { - switch (points) { + private String getScore(int score) { + switch (score) { case 0: return "love"; case 1: return "15" ; case 2: return "30" ; case 3: return "40"; - default: return "40" ; - } +// default: return "40" ; + } + throw new IllegalArgumentException("Illegal score: " + score); } public void player1Scored() throws TennisGameException { @@ -77,7 +78,7 @@ public String getScore() { return "player2 wins"; } - if (player1Points >= 4 && player1Points == player2Points) + if (player1Points >= 3 && player1Points == player2Points) return "deuce"; if (player1Points >= 4 && player1Points - player2Points == 1) diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..9c5c83e 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -1,11 +1,13 @@ import static org.junit.Assert.*; - import org.junit.Test; -import jdk.nashorn.internal.ir.annotations.Ignore; - public class TennisGameTest { + private int player1Points; + private int player2Points; + + private boolean gameEnded; + // Here is the format of the scores: "player1Score - player2Score" // "love - love" // "15 - 15" @@ -20,7 +22,8 @@ public class TennisGameTest { // "player2 has advantage" // "player1 wins" // "player2 wins" - @Ignore +// @Ignore + @Test public void testTennisGame_Start() { //Arrange TennisGame game = new TennisGame(); @@ -31,7 +34,8 @@ public void testTennisGame_Start() { } @Test - public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameException { +// public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameException { + public void testTennisGame_Deuce() throws TennisGameException { //Arrange TennisGame game = new TennisGame(); @@ -52,7 +56,9 @@ public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameE } @Test (expected = TennisGameException.class) - public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() throws TennisGameException { +// @Test +// public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() throws TennisGameException { + public void testTennisGame_ResultsException() throws TennisGameException { //Arrange TennisGame game = new TennisGame(); //Act @@ -62,6 +68,7 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr game.player1Scored(); //Act // This statement should cause an exception - game.player1Scored(); + game.player1Scored(); + } }