From 25d27e376485adda28f1eaaf848e5b306ed41dce Mon Sep 17 00:00:00 2001 From: pahayryn Date: Thu, 20 Sep 2018 16:47:47 +0300 Subject: [PATCH 1/3] Kesken --- bin/TennisGame.class | Bin 1823 -> 1823 bytes bin/TennisGameTest.class | Bin 1393 -> 1746 bytes src/TennisGame.java | 12 ++--- tests/TennisGameTest.java | 33 +++++++++++-- tests/TennisGameTest2.java | 56 +++++++++++++++++++++ tests/TennisGameTest3.java | 98 +++++++++++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 tests/TennisGameTest2.java create mode 100644 tests/TennisGameTest3.java diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 2da4e7a578a8ea5a5a076c2766b0eebecc4efc75..59d0d5ba5b11da1617f6d88a0863f58f3fdaa58a 100644 GIT binary patch delta 13 UcmbQwH=l1qJ{#l0$pvid0U><^+5i9m delta 13 UcmbQwH=l1qJ{#kb$pvid0U?Y8-2eap diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index b202db2907805d8b5bb4b6f773ec5588f796fb7a..422598151cdadd0940ebf552d0e01ae15bc6f700 100644 GIT binary patch delta 773 zcmbV|OHUI~6vzK}rs6Pk;!sLr1mguk9;GcES`>uhW1%KsP@4Em$fUj2(K;p5VZn-x z3$|oFh+(5f6LsyJ1v`0+%Hn&?L^jT!U^SX(W3M+K#gdOJ{!I8sQX80~A>GbMq6nx|wZ z4oT0a3RFEbFc*E)TAKzg2{LJJM|h%5CgOD+51lBb97XidV# z6tc+SG?zJyJS2)3!z?2XUu9HKiC(3qcFX92&Ke*E!RRSkeY9*!rH*-=q+^dMI`#B> z^gnomfz=~`323Ydb}_T?JJ<#EvT~7NO9WeH<0`>c2zHHNyVo&-n`FJksUT%{3==KB z42<%eC&>t#jPZ9G?aTj5oUHMveoo}2KO^7f{B@GtA@W@!ZxHz&k?)h{5s4rFGjWxF H(XjFp%2v#kYU`_tsGX!%y0M(Jqo$fWG93$v#KsRG^Gmux z5V5wj^cSrB0r6JT=;GY_-t(S&&U5dF_N}V#KTod!RdKI>(OlR0|l!B4S8l z3@OggkwBWRU^c_|=4 && player2Points-player1Points>=2) private String getScore(int points) { switch (points) { case 0: return "love"; - case 1: return "15" ; - case 2: return "30" ; + case 1: return "15"; + case 2: return "30"; case 3: return "40"; - default: return "40" ; + default: return "40"; } } @@ -83,9 +83,9 @@ public String getScore() { if (player1Points >= 4 && player1Points - player2Points == 1) return "player1 has advantage"; - if (player2Points > 4 && player2Points - player1Points == 1) + if (player2Points >= 4 && player2Points - player1Points == 1) return "player2 has advantage"; - return player2Score + " - " + player1Score ; + return player2Score + " - " + player1Score; } } \ No newline at end of file diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index 8674eba..d92cb05 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -20,8 +20,9 @@ public class TennisGameTest { // "player2 has advantage" // "player1 wins" // "player2 wins" - @Ignore + @Test public void testTennisGame_Start() { + //Both have zero points //Arrange TennisGame game = new TennisGame(); //Act @@ -62,6 +63,32 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr game.player1Scored(); //Act // This statement should cause an exception - game.player1Scored(); - } + game.player1Scored(); + String score = game.getScore(); + + + //TÄMÄ EI TOIMI VIELÄ OIKEIN!!!!!!! + //Assert + assertEquals("Game has already ended. Player 1 can't get a point", "Game end", score); + } + + @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 + //TÄMÄ EI TOIMI VIELÄ OIKEIN!!!!!!! + game.player2Scored(); + String score = game.getScore(); + + //Assert + assertEquals("Game has already ended. Player 2 can't get a point", "Game end", score); + } + } diff --git a/tests/TennisGameTest2.java b/tests/TennisGameTest2.java new file mode 100644 index 0000000..4751ac0 --- /dev/null +++ b/tests/TennisGameTest2.java @@ -0,0 +1,56 @@ +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TennisGameTest2 { + @Test + public void testTennisGame_Start() { + //Arrange + TennisGame game = new TennisGame(); + //Act + String score = game.getScore() ; + // Assert + assertEquals("Initial score incorrect", "love - love", score); + } + + @Test + public void testTennisGame_Player1Have1MorePoint() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player1Scored(); + + String score = game.getScore() ; + // Assert + assertEquals("Player1 has advantage", "player1 has advantage", score); + + + } + @Test + public void testTennisGame_Player2Have1MorePoint() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player2Scored(); + + String score = game.getScore() ; + // Assert + assertEquals("Player2 has advantage", "player2 has advantage", score); + + + } +} diff --git a/tests/TennisGameTest3.java b/tests/TennisGameTest3.java new file mode 100644 index 0000000..9b5bb92 --- /dev/null +++ b/tests/TennisGameTest3.java @@ -0,0 +1,98 @@ +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TennisGameTest3 { + + @Test + public void testTennisGame_Player1Have1Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + + String score = game.getScore(); + + assertEquals("love - 15", "love - 15", score); + } + @Test + public void testTennisGame_Player1Have2Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + + String score = game.getScore(); + + assertEquals("love - 30", "love - 30", score); + } + + @Test + public void testTennisGame_Player2Have1Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - love", "15 - love", score); + } + @Test + public void testTennisGame_Player2Have2Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - love", "30 - love", score); + } + + @Test + public void testTennisGame_Player1Have1Point_Player2Have1Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - 15", "15 - 15", score) ; + } + + @Test + public void testTennisGame_Player1Have2Point_Player2Have1Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - 30", "15 - 30", score) ; + } + + @Test + public void testTennisGame_Player1Have1Point_Player2Have2Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - 15", "30 - 15", score) ; + } + + @Test + public void testTennisGame_Player1Have2Point_Player2Have2Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - 30", "30 - 30", score) ; + } +} From 91816c2642de3c5c681a8b014f4456ce1a9c6279 Mon Sep 17 00:00:00 2001 From: Paukku <38953125+Paukku@users.noreply.github.com> Date: Fri, 21 Sep 2018 23:01:38 +0300 Subject: [PATCH 2/3] Assignment finished --- bin/TennisGame.class | Bin 1823 -> 1823 bytes bin/TennisGameException.class | Bin 285 -> 285 bytes bin/TennisGameTest.class | Bin 1746 -> 1141 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/bin/TennisGame.class b/bin/TennisGame.class index 59d0d5ba5b11da1617f6d88a0863f58f3fdaa58a..3298d0487f0b9558fe0397ce4e06b37f3c896c14 100644 GIT binary patch delta 17 ZcmbQwH=mE=)W2Q(7#JALHgbrw0{}d51+V}B delta 17 ZcmbQwH=mE=)W2Q(7#J8#Hgbrw0{}c`1+D-9 diff --git a/bin/TennisGameException.class b/bin/TennisGameException.class index d3bcf94f181696416666f8c5713c89dbe0555f1b..094639d0f18ad137359201b37e732175da207fb5 100644 GIT binary patch delta 17 ZcmbQsG?$6v)W2Q(7#JALHgbqE0suO`1&jay delta 17 ZcmbQsG?$6v)W2Q(7#J8#HgbqE0suO+1&ROw diff --git a/bin/TennisGameTest.class b/bin/TennisGameTest.class index 422598151cdadd0940ebf552d0e01ae15bc6f700..5bea34827451fbecf59b99b23c6ece4978c95308 100644 GIT binary patch literal 1141 zcmb`F-)j>=5XWcJ*h{amsj<=4pBH_pFBg;|Vx&+siV(CkG2&C$?2XCB%Wl}+EA3w< zDCoO?lsKD~Ce{Os_^`9g?CfV|zdJvEe)$FfkKtYb1qN$fR7%=ce1cuHE`TC~^)Wx> zjg+fljVQ>VNjXpwv5rH1gi{2@03BS(?d)mp(j(B zawoNlrbZ7^oIH)fmF@^5cRa;toP3HEw?lh6YR-ZFMIQTJw=;gW1Nv@4KHi61lJkV|0)ZE z#<^lGJ`(#WKSuLjs-1mJ64`!7kR1INmg)obghx{v1x!fk1&z)!NT~c8k1k##?C8u0d@21eExf}^ z82itKI?xEx_yYYoqqR&nAa94FjP~#=ls;6$&rtqOUI8j(eU8sxCtE(rf-6uZkBZP~ z0X9yvYPA1JyOu-S%%yD-Z3(uBQY7|`f8gHF<=)ESu2O{>t=j_bT(IdUx$wLH2j0$w KN2Emo>c0Rq?Ee)2 literal 1746 zcmbW1`%V)<7{$*(rAsM_6}(>-uUv#mMZ6SIRJ_U&go|5*|quS=03YO)X zs|0c--;wT$473?HCR5S64k=LDu38irjHuq8T`fm4pzfiiniuI!wW34KH1nS4M>5jB z7iaNDr-*w6(`Bpa~X^2=uxBTV+q!rpw?MPNZ?1^|V3e!%ziL7B+?jvN9emys1f- zz*k2)B@;7suZx{CvExzKdh5CwxDU(dA zPERkgh)P|3?hoEN>l9(b7SiMPMl5Q!9e| zdqtpNQrPP)BJbBfWEx&9h=ld&}5l;Tp5Y-!WETXVSvIl3KVf zaPe;#O^!k*2Y0CK*8)e~)#i#Nw#S_RNpl7;3|>-RaPVT%TlBC^bChQ<%3If`elYX4Q5buOhvFl$qR4l5T#3`!vqZg-fhKd4bsoafoj81Vh(!ubt!7!6x z7$ZmXnc#c#F>~gfj2Ci+?TiIdfSMMyveX&CC9_*`-@6Yt80Mj>N=DWq8t;V Date: Fri, 21 Sep 2018 23:10:44 +0300 Subject: [PATCH 3/3] Assignment finished --- src/TennisGame.java | 2 +- tests/TennisGameTest.java | 137 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 132 insertions(+), 7 deletions(-) diff --git a/src/TennisGame.java b/src/TennisGame.java index 96eb49b..e989571 100644 --- a/src/TennisGame.java +++ b/src/TennisGame.java @@ -1,7 +1,7 @@ // This implementation is used for practicing unit tests. // NOTE THAT it may contain bugs // Write unit tests in TennisGameTest.java and try to find the errors in the code - +//Try fix bugs public class TennisGame { private int player1Points; private int player2Points; diff --git a/tests/TennisGameTest.java b/tests/TennisGameTest.java index d92cb05..9ee82ed 100644 --- a/tests/TennisGameTest.java +++ b/tests/TennisGameTest.java @@ -2,8 +2,6 @@ import org.junit.Test; -import jdk.nashorn.internal.ir.annotations.Ignore; - public class TennisGameTest { // Here is the format of the scores: "player1Score - player2Score" @@ -66,10 +64,8 @@ public void testTennisGame_Player1WinsPointAfterGameEnded_ResultsException() thr game.player1Scored(); String score = game.getScore(); - - //TÄMÄ EI TOIMI VIELÄ OIKEIN!!!!!!! //Assert - assertEquals("Game has already ended. Player 1 can't get a point", "Game end", score); + assertEquals("Player 1 win", "40", score); } @Test (expected = TennisGameException.class) @@ -88,7 +84,136 @@ public void testTennisGame_Player2WinsPointAfterGameEnded_ResultsException() thr String score = game.getScore(); //Assert - assertEquals("Game has already ended. Player 2 can't get a point", "Game end", score); + assertEquals("Player 2 win", "40", score); + } + @Test + public void testTennisGame_Player1Have1MorePoint() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player1Scored(); + + String score = game.getScore() ; + // Assert + assertEquals("Player1 has advantage", "player1 has advantage", score); + + + } + @Test + public void testTennisGame_Player2Have1MorePoint() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + game.player1Scored(); + + game.player2Scored(); + game.player2Scored(); + game.player2Scored(); + + game.player2Scored(); + + String score = game.getScore() ; + // Assert + assertEquals("Player2 has advantage", "player2 has advantage", score); + } + @Test + public void testTennisGame_Player1Have1Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + + String score = game.getScore(); + + assertEquals("love - 15", "love - 15", score); + } + @Test + public void testTennisGame_Player1Have2Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player1Scored(); + game.player1Scored(); + + String score = game.getScore(); + + assertEquals("love - 30", "love - 30", score); + } + + @Test + public void testTennisGame_Player2Have1Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - love", "15 - love", score); + } + @Test + public void testTennisGame_Player2Have2Point() throws TennisGameException { + TennisGame game = new TennisGame(); + + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - love", "30 - love", score); + } + + @Test + public void testTennisGame_Player1Have1Point_Player2Have1Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - 15", "15 - 15", score) ; + } + + @Test + public void testTennisGame_Player1Have2Point_Player2Have1Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("15 - 30", "15 - 30", score) ; + } + + @Test + public void testTennisGame_Player1Have1Point_Player2Have2Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - 15", "30 - 15", score) ; } + @Test + public void testTennisGame_Player1Have2Point_Player2Have2Point() throws TennisGameException{ + TennisGame game = new TennisGame(); + game.player1Scored(); + game.player1Scored(); + game.player2Scored(); + game.player2Scored(); + + String score = game.getScore(); + + assertEquals("30 - 30", "30 - 30", score) ; + } + }