From 47020c538af2dcdaf6aaac369040252d3e68561d Mon Sep 17 00:00:00 2001 From: EkaterinaLeonenko <43238204+EkaterinaLeonenko@users.noreply.github.com> Date: Thu, 20 Sep 2018 15:06:10 +0300 Subject: [PATCH 1/2] c --- tests/TennisGameTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..8f2c728 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -51,6 +51,7 @@ public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameE assertEquals("Tie score incorrect", "deuce", score); } + @Test (expected = TennisGameException.class) public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() throws TennisGameException { //Arrange From bad43ece049bcf67d025c0f727026d572a3f7ca6 Mon Sep 17 00:00:00 2001 From: EkaterinaLeonenko <43238204+EkaterinaLeonenko@users.noreply.github.com> Date: Fri, 21 Sep 2018 23:00:15 +0300 Subject: [PATCH 2/2] Assignment Finished --- bin/.gitignore | 4 + bin/TennisGame.class | Bin 1823 -> 1823 bytes bin/TennisGameTest.class | Bin 1393 -> 1393 bytes src/TennisGame.java | 13 ++- tests/TennisGameTest_.java | 185 +++++++++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 bin/.gitignore create mode 100644 tests/TennisGameTest_.java diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..f69d4b9 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,4 @@ +/TennisGame.class +/TennisGameException.class +/TennisGameTest.class +/TennisGameTest_.class diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7a578a8ea5a5a076c2766b0eebecc4efc75..ab8841f2e804d4b74dcc9fc3b328323b46741b2b 100644 GIT binary patch delta 63 zcmbQwH=l2V0~;gTWJfkV#)Xp$*u;3XcQDv)XK)sB+s5FbGkG$bk!Uc314AefhA~6{ QVJ<^7LjgnVV!Z delta 63 zcmbQwH=l2V0~;gzWJfkV#wC*r*u;2sb}-m(XK)sB+s5FbJ$W*lk!T=;14A%FC_@NC T1Vb1@E<-p&0Yl{ETWqcX2$&DS diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index b202db2907805d8b5bb4b6f773ec5588f796fb7a..143c4cc84d566210dfc912abe573b2fc8c793e61 100644 GIT binary patch delta 37 scmey!^^t3X5v!yX0|$c*0}q2Og8+jag9w8?g9L*UgA9Z7WN%hA0F3koApigX delta 37 scmey!^^t3X5v!yn0|$dO0}q1@g8+jqg9w8ig9L*kgA9YyWN%hA0E~SG8UO$Q diff --git a/src/TennisGame.java b/src/TennisGame.java index 327f284..c64d392 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -77,15 +77,22 @@ public String getScore() { return "player2 wins"; } - if (player1Points >= 4 && player1Points == player2Points) + if (player1Points >= 3 && player1Points == player2Points) + //before: if (player1Points >= 4 && player1Points == player2Points) + //Should be at least 3 points, not 4 return "deuce"; if (player1Points >= 4 && player1Points - player2Points == 1) return "player1 has advantage"; - if (player2Points > 4 && player2Points - player1Points == 1) + if (player2Points >= 4 && player2Points - player1Points == 1) + //before: if (player2Points > 4 && player2Points - player1Points == 1) + //Should be >=, not just > return "player2 has advantage"; - return player2Score + " - " + player1Score ; + return player1Score + " - " + player2Score ; + //before: return player2Score + " - " + player1Score ; + //Wrong order of players in score fixed + } } \ No newline at end of file diff --git a/tests/TennisGameTest_.java b/tests/TennisGameTest_.java new file mode 100644 index 0000000..cc4c339 --- /dev/null +++ b/tests/TennisGameTest_.java @@ -0,0 +1,185 @@ +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TennisGameTest_ { + + @Test + +public void testTennisGame_firstplayerWins() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + + game.player1Scored(); + + //Act + String score = game.getScore() ; + // Assert + assertEquals("Player1 wins incorrect", "player1 wins", score); + } + + @Test + public void testTennisGame_2playerWins() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player1Scored(); + + game.player2Scored(); + + //Act + String score = game.getScore() ; + // Assert + assertEquals("Player2 wins incorrect", "player2 wins", score); + } + @Test + + +public void testTennisGame_describingScorelove() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + //Act + String score = game.getScore() ; + // Assert + assertEquals("love incorrect", "love - love", score); + + } + + @Test +// This test failed +// Because of bug in public getScore (wrong players order, fixed) + +/* + * We can't test individual scores, because they are in private getScore method, + * so we should test public getScore for score of two players + */ +public void testTennisGame_describingScore15() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + game.player1Scored(); + //Act + String score = game.getScore() ; + // Assert + assertEquals("15 incorrect", "15 - love", score); + + } + + @Test +//This test failed +// Because of bug in public getScore (wrong players order, fixed) + +/* + * We can't test individual scores, because they are in private getScore method, + * so we should test public getScore for score of two players + */ +public void testTennisGame_describingScore30() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + //Act + String score = game.getScore() ; + // Assert + assertEquals("30 incorrect", "30 - love", score); + + } + +@Test +//This test failed +//Because of bug in public getScore (wrong players order, fixed) + +/* + * We can't test individual scores, because they are in private getScore method, + * so we should test public getScore for score of two players + */ +public void testTennisGame_describingScore40() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + //Act + String score = game.getScore() ; + // Assert + assertEquals("40 incorrect", "40 - love", score); + + } + +@Test +//This test failed +//Bug in getScore for deuce, 4 points instead 3, fixed +public void testTennisGame_deuce() 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("deuce incorrect", "deuce", score); + } + +@Test + +public void testTennisGame_advantage() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player1Scored(); + + //Act + String score = game.getScore() ; + // Assert + assertEquals("player1 has advantage incorrect", "player1 has advantage", score); + } + +@Test +//This test failed +//if (player2Points > 4 && player2Points - player1Points == 1) +//Should be >=, not just > +//fixed +public void testTennisGame_advantage2() throws TennisGameException { + //Arrange + TennisGame game = new TennisGame(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + + //Act + String score = game.getScore() ; + // Assert + assertEquals("player2 has advantage incorrect", "player2 has advantage", score); + } +} \ No newline at end of file