From 1a7ac5aa4729a8eee15789a80ffc602cb99646a7 Mon Sep 17 00:00:00 2001 From: oskari Date: Thu, 20 Sep 2018 16:24:02 +0300 Subject: [PATCH] Assignment finished --- bin/TennisGame.class | Bin 1823 -> 1823 bytes bin/TennisGameTest.class | Bin 1393 -> 3669 bytes src/TennisGame.java | 10 +-- tests/TennisGameTest.java | 125 +++++++++++++++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 6 deletions(-) diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7a578a8ea5a5a076c2766b0eebecc4efc75..32f2bfd19bcca82bd02873910c66f2d1590a5c0d 100644 GIT binary patch delta 37 tcmbQwH=l1qJ{#l0$pvg;yxKb$Y_~Hw3%PA$@X(n&nazzcdh#tcR{+}@3vd7c delta 37 tcmbQwH=l1qJ{#kb$pvg;ygEA=Y_~Hw3%PA$@X($-nazzca`G)UR{+~{3vmDd diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index b202db2907805d8b5bb4b6f773ec5588f796fb7a..651db15270cb13bec80cc0daede352b9ed448932 100644 GIT binary patch literal 3669 zcmbW3Ygg1(6o%g*Ispg82q>sHT5Guoa|2sNp{S@RDwPqj)sA5%9fD&9CmAojY482e zd+S=g*Y-nitNmavYIUvtfc}L3n6ADj$z(FauyC;;IZ4jR-p_vbK0EWzfA{|e(1&vY z)JRyB&I(2f@_PHXvuI-S)dC}X*lnw?bhy0~{A)><>VNe5%)UI!#JS@d3d znw+rIJpHzwEEtx4QJd6Foo0p&BWJ0Wo-=GKxqK!(TOe3iunz>FNT@FvsmB`BiBoeB zEm$W(&S=&|Dwii-Q%C1mDa;8guN#>G8Lbl5jnbg5W<#b}8PW|7d5R!ogM^jY++{7) z6B0u`HequB?Tn`cGHjY!-U=dwEfRvNeK&Hcpk@iYt7E=P-xEjcf%#8t#WTzhE&7zB zYRhd#A@;mjB!nv@9Z_de<5~5ZmOrff5NXHzU?Uzt}WjvCMM`Y~f%6Nn;;}HoP7qTg;OvaPUud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kcLW8`wgLq;c^46K95vXie2Cs^D^QSyh8z~KCV8yG z3UVA4@RxJlU-QrJcY1uUUR8U}Qf z2<22Q(>+zx=}!q_=$IkjAdW^+p{{kAh|jUQWZI%q07JvVp47GF)^w%c_@|yjoY+m` Zw`tNosUMK~A*pvr{Yd7Od^Fs&`3+@hS4jW> diff --git a/src/TennisGame.java b/src/TennisGame.java index 327f284..380732a 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -28,7 +28,7 @@ private String getScore(int points) { case 2: return "30" ; case 3: return "40"; default: return "40" ; - } + } } public void player1Scored() throws TennisGameException { @@ -83,9 +83,11 @@ public String getScore() { if (player1Points >= 4 && player1Points - player2Points == 1) return "player1 has advantage"; - if (player2Points > 4 && player2Points - player1Points == 1) - return "player2 has advantage"; + if (player2Points >= 4 && player2Points - player1Points == 1) + return "player2 has advantage"; + //there is a bug in the if statemen above. player2Points > 4, should be player2points >= 4 - return player2Score + " - " + player1Score ; + //return player2Score + " - " + player1Score ; <-- A bug, the score return should be player1score - player2score + return player1Score + " - " + player2Score; } } \ No newline at end of file diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..fac0231 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -20,7 +20,8 @@ public class TennisGameTest { // "player2 has advantage" // "player1 wins" // "player2 wins" - @Ignore + + @Test public void testTennisGame_Start() { //Arrange TennisGame game = new TennisGame(); @@ -63,5 +64,125 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr //Act // This statement should cause an exception game.player1Scored(); - } + } + + @Test (expected = TennisGameException.class) + public void testTennisGame_Player2WinsPointAfterGameEnded_ResultsException() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + //Act + //This statement should cause an exception + game.player2Scored(); + } + + @Test + public void testTennisGame_score_15_15() throws TennisGameException { + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + String score = game.getScore(); + assertEquals("Tie score incorrect", "15 - 15", score); + } + + @Test + public void testTennisGame_score_30_30() throws TennisGameException { + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + game.player1Scored(); + game.player2Scored(); + String score = game.getScore(); + assertEquals("Tie score incorrect", "30 - 30", score); + } + + @Test + public void testTennisGame_score_15_love() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + String score = game.getScore(); + assertEquals("Score is incorrect", "15 - love", score); + } + + @Test + public void testTennisGame_score_love_15() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player2Scored(); + String score = game.getScore(); + assertEquals("Score is incorrect", "love - 15", score); + } + + @Test + public void testTennisGame_player1AdvantageToWin() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + game.player1Scored(); + String score = game.getScore(); + assertEquals("Score is incorrect", "player1 has advantage", score); + game.player2Scored(); + score = game.getScore(); + assertEquals("Score is incorrect", "deuce", score); + game.player1Scored(); + game.player1Scored(); + score = game.getScore(); + assertEquals("Result is incorrect", "player1 wins", score); + } + + @Test + public void testTennisGame_player1_win_love() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + String score = game.getScore(); + assertEquals("Score is incorrect", "40 - love", score); + game.player1Scored(); + score = game.getScore(); + assertEquals("Result is incorrect", "player1 wins", score); + } + + @Test + public void testTennisGame_player2_win_love() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + String score = game.getScore(); + assertEquals("Score is incorrect", "love - 40", score); + game.player2Scored(); + score = game.getScore(); + assertEquals("Result is incorrect", "player2 wins", score); + } + + @Test (expected = TennisGameException.class) + public void testTennisGame_otherPlayerMakesPointAfterGameEnd() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + //this should cause an exception + game.player2Scored(); + } + + @Test + public void testTennisGame_player2AdvantageToWin() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + String score = game.getScore(); + assertEquals("advantage - 15", "player2 has advantage", score); + } }