made the test code more realistic - have each player score a point in turn instead of all at once.

This commit is contained in:
emilybache 2012-11-21 10:59:47 +01:00
parent 52fb51eede
commit 1cf0963de5
4 changed files with 28 additions and 16 deletions

View File

@ -71,10 +71,13 @@ public class TennisTest {
@Test @Test
public void checkAllScores() { public void checkAllScores() {
TennisGame game = new TennisGame("player1", "player2"); TennisGame game = new TennisGame("player1", "player2");
for (int i = 0; i < this.player1Score; i++) int highestScore = Math.max(this.player1Score, this.player2Score);
game.wonPoint("player1"); for (int i = 0; i < highestScore; i++) {
for (int i = 0; i < this.player2Score; i++) if (i < this.player1Score)
game.wonPoint("player2"); game.wonPoint("player1");
if (i < this.player2Score)
game.wonPoint("player2");
}
assertEquals(this.expectedScore, game.getScore()); assertEquals(this.expectedScore, game.getScore());
} }

View File

@ -71,10 +71,13 @@ public class TennisTest {
@Test @Test
public void checkAllScores() { public void checkAllScores() {
TennisGame game = new TennisGame("player1", "player2"); TennisGame game = new TennisGame("player1", "player2");
for (int i = 0; i < this.player1Score; i++) int highestScore = Math.max(this.player1Score, this.player2Score);
game.wonPoint("player1"); for (int i = 0; i < highestScore; i++) {
for (int i = 0; i < this.player2Score; i++) if (i < this.player1Score)
game.wonPoint("player2"); game.wonPoint("player1");
if (i < this.player2Score)
game.wonPoint("player2");
}
assertEquals(this.expectedScore, game.getScore()); assertEquals(this.expectedScore, game.getScore());
} }

View File

@ -71,10 +71,13 @@ public class TennisTest {
@Test @Test
public void checkAllScores() { public void checkAllScores() {
TennisGame game = new TennisGame("player1", "player2"); TennisGame game = new TennisGame("player1", "player2");
for (int i = 0; i < this.player1Score; i++) int highestScore = Math.max(this.player1Score, this.player2Score);
game.wonPoint("player1"); for (int i = 0; i < highestScore; i++) {
for (int i = 0; i < this.player2Score; i++) if (i < this.player1Score)
game.wonPoint("player2"); game.wonPoint("player1");
if (i < this.player2Score)
game.wonPoint("player2");
}
assertEquals(this.expectedScore, game.getScore()); assertEquals(this.expectedScore, game.getScore());
} }

View File

@ -70,10 +70,13 @@ public class TennisTest {
@Test @Test
public void checkAllScores() { public void checkAllScores() {
TennisGame game = new TennisGame("player1", "player2"); TennisGame game = new TennisGame("player1", "player2");
for (int i = 0; i < this.player1Score; i++) int highestScore = Math.max(this.player1Score, this.player2Score);
game.wonPoint("player1"); for (int i = 0; i < highestScore; i++) {
for (int i = 0; i < this.player2Score; i++) if (i < this.player1Score)
game.wonPoint("player2"); game.wonPoint("player1");
if (i < this.player2Score)
game.wonPoint("player2");
}
assertEquals(this.expectedScore, game.getScore()); assertEquals(this.expectedScore, game.getScore());
} }