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
4 changes: 4 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/TennisGame.class
/TennisGameException.class
/TennisGameTest.class
/TennisGameTest2.class
Binary file modified bin/TennisGame.class
Binary file not shown.
Binary file modified bin/TennisGameTest.class
Binary file not shown.
2 changes: 1 addition & 1 deletion src/TennisGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ public String getScore() {
if (player2Points > 4 && player2Points - player1Points == 1)
return "player2 has advantage";

return player2Score + " - " + player1Score ;
return player1Score + " - " + player2Score ;
}
}
32 changes: 23 additions & 9 deletions tests/TennisGameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TennisGameTest {
// "player2 has advantage"
// "player1 wins"
// "player2 wins"
@Ignore
@Test
public void testTennisGame_Start() {
//Arrange
TennisGame game = new TennisGame();
Expand All @@ -31,24 +31,20 @@ public void testTennisGame_Start() {
}

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

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

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

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

@Test (expected = TennisGameException.class)
Expand All @@ -62,6 +58,24 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr
game.player1Scored();
//Act
// This statement should cause an exception
game.player1Scored();
//game.player1Scored();
String i = game.getScore();
assertSame(i, "player1 wins");

}
@Test (expected = TennisGameException.class)
public void testTennisGame_Player2WinsPointAfterGameEnded_ResultsException() throws TennisGameException {
//Arrange
TennisGame game = new TennisGame();
//Act
game.player2Scored();
game.player2Scored();
game.player2Scored();
game.player2Scored();
//Act
// This statement should cause an exception
//game.player1Scored();
String i = game.getScore();
assertSame(i, "player2 wins");
}
}
25 changes: 25 additions & 0 deletions tests/TennisGameTest2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import static org.junit.Assert.*;

import org.junit.Test;

public class TennisGameTest2 {

@Test
public void testPlayer2wins()throws TennisGameException {
// Arrange
TennisGame game = new TennisGame();
//Act
game.player2Scored();
game.player2Scored();
game.player2Scored();
game.player1Scored();
game.player1Scored();
game.player1Scored();
game.player2Scored();
game.player2Scored();
//fail("Not yet implemented");
String i = game.getScore();
assertSame(i, "player2 wins");
}

}