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/TennisGameException.class
Binary file not shown.
Binary file modified bin/TennisGameTest.class
Binary file not shown.
11 changes: 6 additions & 5 deletions src/TennisGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 14 additions & 7 deletions tests/TennisGameTest.java
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -62,6 +68,7 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr
game.player1Scored();
//Act
// This statement should cause an exception
game.player1Scored();
game.player1Scored();

}
}