From ea53714968b8220414b6a33a54076b0a9bd3746d Mon Sep 17 00:00:00 2001 From: juhlgren Date: Thu, 20 Sep 2018 15:19:35 +0300 Subject: [PATCH 1/2] argh --- bin/TennisGameTest.class | Bin 1393 -> 1393 bytes src/TennisGame.java | 4 ++-- tests/TennisGameTest.java | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index b202db2907805d8b5bb4b6f773ec5588f796fb7a..7eed038645a1864ef678f01b9d84de76ac2880a9 100644 GIT binary patch delta 17 Ycmey!^^t3X8!M|bgA9YqWN%hA05i@6qW}N^ delta 17 Ycmey!^^t3X8!M|LgA9YyWN%hA05h@#p8x;= diff --git a/src/TennisGame.java b/src/TennisGame.java index 327f284..ab59181 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -66,10 +66,10 @@ public String getScore() { // "player2 has advantage" // "player1 wins" // "player2 wins" - +// testing push, why dont it do it. String player1Score = getScore(player1Points); String player2Score = getScore(player2Points); - + String kettujenkevat; if (gameEnded) { if (player1Points > player2Points) return "player1 wins"; diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..1536073 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -60,6 +60,8 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr game.player1Scored(); game.player1Scored(); game.player1Scored(); + // testing push + //Act // This statement should cause an exception game.player1Scored(); From a9177c41cacd10c905b123904ac6983ac0b73792 Mon Sep 17 00:00:00 2001 From: Sonofhades Date: Fri, 21 Sep 2018 02:17:52 +0300 Subject: [PATCH 2/2] Assignment 1 finished --- bin/TennisGame.class | Bin 1823 -> 1823 bytes bin/TennisGameTest.class | Bin 1393 -> 3193 bytes src/TennisGame.java | 41 +++++----- tests/TennisGameTest.java | 166 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 182 insertions(+), 25 deletions(-) diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7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PWkA&fC&40R8gus#eCW>We(!rS;0sLXgBXs=QsYNa~uax6BnQ0n#EPe6gl zXNl@Oi9%<%i31-H;8k|zLjt@?fFH5V*Vwj?x#K?J?)o&) z>Vz-eE>Ap_!}Vl@C&PcWTDfy-Ih2%Z6@|WlYkke9tC|NXT_>d*q;!*%KBseUkkS{V z^d%|XBBk3aL`k{#)JjqEyY%`}l=w@)JyQCXlaMILP`&4ykAM_H&XhYl>Q*4KUav7GG3NOufv&t0Y9Bd ASO5S3 delta 392 zcmYjMO-lk%6g_WJnMs=YOWYI` zMC+C zdfb-W5W?{c&vt~%FWbVAR)3IZO2_nv?960{HyqjK-FsnsylJ^!T|)xJD7Fz{h~4#! z2TPW(O`2;33XfuEN~w$$6%~e5)3$PM;LO>AinL5mMb&>&dj23(Vj+Jn{LKpfPk3cR z*IzI}iTDITFW~8`WI4I(XCvLmJwz~rP5NsH3|m+rHczZT*f(*2S!&o&=m6PwByL`j zYE0!%_UL^wDA4F$8x7T player2Points) return "player1 wins"; @@ -77,15 +77,18 @@ public String getScore() { return "player2 wins"; } - if (player1Points >= 4 && player1Points == player2Points) - return "deuce"; + // original fails as 40-40 when both have scored 3 points because deuce is already at 3-3) + if (player1Points >= 3 && player1Points == player2Points) + return "deuce"; if (player1Points >= 4 && player1Points - player2Points == 1) return "player1 has advantage"; - if (player2Points > 4 && player2Points - player1Points == 1) + // original was missing =, resulting in a 40-40 score instead of advantage being reported + if (player2Points >= 4 && player2Points - player1Points == 1) return "player2 has advantage"; - return player2Score + " - " + player1Score ; + // testing found that player scores were listed in reverse order + return player1Score + " - " + player2Score ; } } \ No newline at end of file diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 1536073..5359b0d 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -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(); @@ -31,7 +31,7 @@ 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(); @@ -55,15 +55,169 @@ public void testTennisGame_EahcPlayerWin4Points_Score_Deuce() throws TennisGameE public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() throws TennisGameException { //Arrange TennisGame game = new TennisGame(); + String score; //Act game.player1Scored(); game.player1Scored(); game.player1Scored(); game.player1Scored(); - // testing push + //Act - // This statement should cause an exception - game.player1Scored(); - } + // This statement should cause an exception according to teacher. Why? Should't the program have ended already by this time? + game.player1Scored(); + score=game.getScore(); + System.out.println(score); + + //Assert + assertEquals("failure when game has already ended", "player1 wins", score); + + } + + @Test // tests 3-3 deuce + public void deuce_testi() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + int i; + for (i=0; i<3; i++) + { + game.player2Scored(); + game.player1Scored(); + } + //Act + + score = game.getScore() ; + + + // Assert + assertEquals("Deuce fails", "deuce", score); + + } + + @Test // tests 1-0 15-love - apparently score was reported in the wrong fashion + public void fifteen_love_test() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + //Act + game.player1Scored(); + score = game.getScore() ; + + + // Assert + assertEquals("fails", "15 - love", score); + + } + + @Test // tests 1-0 15-love - apparently score was reported in the wrong fashion + public void love_fifteen_test() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + //Act + game.player2Scored(); + score = game.getScore() ; + + + // Assert + assertEquals("fails", "love - 15", score); + } + + // There would normally be different tests for 30-15, 15-30, 30-30 etc, but they hardly seem necessary. + // could be tested in a loop that prints each score as the game progresses. + + @Test + public void player1_wins_test() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + int i; + //Act + for (i=0;i<3;i++) + { + game.player1Scored(); + + } + game.player2Scored(); + game.player1Scored(); + score = game.getScore() ; + + + // Assert + assertEquals("fails", "player1 wins", score); + } + + + + @Test + public void player2_advantage() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + int i; + //Act + for (i=0;i<3;i++) + { + game.player1Scored(); + game.player2Scored(); + } + // score is now 40-40 (i.e. 3-3) + game.player2Scored(); + score = game.getScore(); + + // Assert + assertEquals("fails", "player2 has advantage", score); + + } + + @Test + public void player1_advantage() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + int i; + //Act + for (i=0;i<3;i++) + { + game.player1Scored(); + game.player2Scored(); + } + // score is now 40-40 (i.e. 3-3) + game.player1Scored(); + score = game.getScore(); + + // Assert + assertEquals("fails", "player1 has advantage", score); + + } + + @Test + public void player2_wins_test() throws TennisGameException + { + //Arrange + TennisGame game = new TennisGame(); + String score; + int i; + //Act + for (i=0;i<3;i++) + { + game.player2Scored(); + } + game.player1Scored(); + game.player2Scored(); + score = game.getScore() ; + + // Assert + assertEquals("fails", "player2 wins", score); + + } + + }