mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 20:32:15 +00:00
C# version now available in cyber-dojo
This commit is contained in:
parent
e2a9c5468d
commit
c2d3a90bc9
@ -24,4 +24,5 @@ As an alternative to downloading the code, click one of the links below to creat
|
||||
- [Python](http://cyber-dojo.com/forker/fork/FFEB8EE18C?avatar=cheetah&tag=3)
|
||||
- [Ruby](http://cyber-dojo.com/forker/fork/9197D6B12C?avatar=cheetah&tag=3)
|
||||
- [Java](http://cyber-dojo.com/forker/fork/B22DCD17C3?avatar=buffalo&tag=11)
|
||||
- [C++](http://cyber-dojo.com/forker/fork/CD6FC41518?avatar=deer&tag=45)
|
||||
- [C++](http://cyber-dojo.com/forker/fork/CD6FC41518?avatar=deer&tag=45)
|
||||
- [C#](http://cyber-dojo.com/forker/fork/672E047F5D?avatar=buffalo&tag=7)
|
||||
@ -2,11 +2,11 @@ using System;
|
||||
|
||||
namespace Tennis
|
||||
{
|
||||
public interface TennisGame
|
||||
{
|
||||
void WonPoint (string playerName);
|
||||
string GetScore ();
|
||||
public interface TennisGame
|
||||
{
|
||||
void WonPoint (string playerName);
|
||||
string GetScore ();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,87 +3,87 @@ using NUnit.Framework;
|
||||
|
||||
namespace Tennis
|
||||
{
|
||||
class TennisGame1 : TennisGame
|
||||
{
|
||||
private int m_score1 = 0;
|
||||
private int m_score2 = 0;
|
||||
private string player1Name;
|
||||
private string player2Name;
|
||||
class TennisGame1 : TennisGame
|
||||
{
|
||||
private int m_score1 = 0;
|
||||
private int m_score2 = 0;
|
||||
private string player1Name;
|
||||
private string player2Name;
|
||||
|
||||
public TennisGame1 (string player1Name, string player2Name)
|
||||
{
|
||||
this.player1Name = player1Name;
|
||||
this.player2Name = player2Name;
|
||||
}
|
||||
public TennisGame1 (string player1Name, string player2Name)
|
||||
{
|
||||
this.player1Name = player1Name;
|
||||
this.player2Name = player2Name;
|
||||
}
|
||||
|
||||
public void WonPoint (string playerName)
|
||||
{
|
||||
if (playerName == "player1")
|
||||
m_score1 += 1;
|
||||
else
|
||||
m_score2 += 1;
|
||||
}
|
||||
public void WonPoint (string playerName)
|
||||
{
|
||||
if (playerName == "player1")
|
||||
m_score1 += 1;
|
||||
else
|
||||
m_score2 += 1;
|
||||
}
|
||||
|
||||
public string GetScore ()
|
||||
{
|
||||
String score = "";
|
||||
int tempScore=0;
|
||||
if (m_score1==m_score2)
|
||||
{
|
||||
switch (m_score1)
|
||||
{
|
||||
case 0:
|
||||
score = "Love-All";
|
||||
break;
|
||||
case 1:
|
||||
score = "Fifteen-All";
|
||||
break;
|
||||
case 2:
|
||||
score = "Thirty-All";
|
||||
break;
|
||||
case 3:
|
||||
score = "Forty-All";
|
||||
break;
|
||||
default:
|
||||
score = "Deuce";
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if (m_score1>=4 || m_score2>=4)
|
||||
{
|
||||
int minusResult = m_score1-m_score2;
|
||||
if (minusResult==1) score ="Advantage player1";
|
||||
else if (minusResult ==-1) score ="Advantage player2";
|
||||
else if (minusResult>=2) score = "Win for player1";
|
||||
else score ="Win for player2";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=1; i<3; i++)
|
||||
{
|
||||
if (i==1) tempScore = m_score1;
|
||||
else { score+="-"; tempScore = m_score2;}
|
||||
switch(tempScore)
|
||||
{
|
||||
case 0:
|
||||
score+="Love";
|
||||
break;
|
||||
case 1:
|
||||
score+="Fifteen";
|
||||
break;
|
||||
case 2:
|
||||
score+="Thirty";
|
||||
break;
|
||||
case 3:
|
||||
score+="Forty";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return score;
|
||||
}
|
||||
}
|
||||
public string GetScore ()
|
||||
{
|
||||
String score = "";
|
||||
int tempScore=0;
|
||||
if (m_score1==m_score2)
|
||||
{
|
||||
switch (m_score1)
|
||||
{
|
||||
case 0:
|
||||
score = "Love-All";
|
||||
break;
|
||||
case 1:
|
||||
score = "Fifteen-All";
|
||||
break;
|
||||
case 2:
|
||||
score = "Thirty-All";
|
||||
break;
|
||||
case 3:
|
||||
score = "Forty-All";
|
||||
break;
|
||||
default:
|
||||
score = "Deuce";
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if (m_score1>=4 || m_score2>=4)
|
||||
{
|
||||
int minusResult = m_score1-m_score2;
|
||||
if (minusResult==1) score ="Advantage player1";
|
||||
else if (minusResult ==-1) score ="Advantage player2";
|
||||
else if (minusResult>=2) score = "Win for player1";
|
||||
else score ="Win for player2";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=1; i<3; i++)
|
||||
{
|
||||
if (i==1) tempScore = m_score1;
|
||||
else { score+="-"; tempScore = m_score2;}
|
||||
switch(tempScore)
|
||||
{
|
||||
case 0:
|
||||
score+="Love";
|
||||
break;
|
||||
case 1:
|
||||
score+="Fifteen";
|
||||
break;
|
||||
case 2:
|
||||
score+="Thirty";
|
||||
break;
|
||||
case 3:
|
||||
score+="Forty";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return score;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2,143 +2,143 @@ using System;
|
||||
|
||||
namespace Tennis
|
||||
{
|
||||
public class TennisGame2 : TennisGame
|
||||
{
|
||||
public int P1point = 0;
|
||||
public int P2point = 0;
|
||||
|
||||
public string P1res = "";
|
||||
public string P2res = "";
|
||||
private string player1Name;
|
||||
private string player2Name;
|
||||
public class TennisGame2 : TennisGame
|
||||
{
|
||||
public int P1point = 0;
|
||||
public int P2point = 0;
|
||||
|
||||
public string P1res = "";
|
||||
public string P2res = "";
|
||||
private string player1Name;
|
||||
private string player2Name;
|
||||
|
||||
public TennisGame2 (string player1Name, string player2Name)
|
||||
{
|
||||
this.player1Name = player1Name;
|
||||
this.player2Name = player2Name;
|
||||
}
|
||||
public TennisGame2 (string player1Name, string player2Name)
|
||||
{
|
||||
this.player1Name = player1Name;
|
||||
this.player2Name = player2Name;
|
||||
}
|
||||
|
||||
public string GetScore(){
|
||||
string score = "";
|
||||
if (P1point == P2point && P1point < 4)
|
||||
{
|
||||
if (P1point==0)
|
||||
score = "Love";
|
||||
if (P1point==1)
|
||||
score = "Fifteen";
|
||||
if (P1point==2)
|
||||
score = "Thirty";
|
||||
if (P1point==3)
|
||||
score = "Forty";
|
||||
score += "-All";
|
||||
}
|
||||
if (P1point==P2point && P1point>3)
|
||||
score = "Deuce";
|
||||
|
||||
if (P1point > 0 && P2point==0)
|
||||
{
|
||||
if (P1point==1)
|
||||
P1res = "Fifteen";
|
||||
if (P1point==2)
|
||||
P1res = "Thirty";
|
||||
if (P1point==3)
|
||||
P1res = "Forty";
|
||||
|
||||
P2res = "Love";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
if (P2point > 0 && P1point==0)
|
||||
{
|
||||
if (P2point==1)
|
||||
P2res = "Fifteen";
|
||||
if (P2point==2)
|
||||
P2res = "Thirty";
|
||||
if (P2point==3)
|
||||
P2res = "Forty";
|
||||
|
||||
P1res = "Love";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
|
||||
if (P1point>P2point && P1point < 4)
|
||||
{
|
||||
if (P1point==2)
|
||||
P1res="Thirty";
|
||||
if (P1point==3)
|
||||
P1res="Forty";
|
||||
if (P2point==1)
|
||||
P2res="Fifteen";
|
||||
if (P2point==2)
|
||||
P2res="Thirty";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
if (P2point>P1point && P2point < 4)
|
||||
{
|
||||
if (P2point==2)
|
||||
P2res="Thirty";
|
||||
if (P2point==3)
|
||||
P2res="Forty";
|
||||
if (P1point==1)
|
||||
P1res="Fifteen";
|
||||
if (P1point==2)
|
||||
P1res="Thirty";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
|
||||
if (P1point > P2point && P2point >= 3)
|
||||
{
|
||||
score = "Advantage player1";
|
||||
}
|
||||
|
||||
if (P2point > P1point && P1point >= 3)
|
||||
{
|
||||
score = "Advantage player2";
|
||||
}
|
||||
|
||||
if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2)
|
||||
{
|
||||
score = "Win for player1";
|
||||
}
|
||||
if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2)
|
||||
{
|
||||
score = "Win for player2";
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
public void SetP1Score(int number){
|
||||
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
P1Score();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetP2Score(int number){
|
||||
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
P2Score();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void P1Score(){
|
||||
P1point++;
|
||||
}
|
||||
|
||||
public void P2Score(){
|
||||
P2point++;
|
||||
}
|
||||
|
||||
public void WonPoint(string player) {
|
||||
if (player == "player1")
|
||||
P1Score();
|
||||
else
|
||||
P2Score();
|
||||
}
|
||||
public string GetScore(){
|
||||
string score = "";
|
||||
if (P1point == P2point && P1point < 4)
|
||||
{
|
||||
if (P1point==0)
|
||||
score = "Love";
|
||||
if (P1point==1)
|
||||
score = "Fifteen";
|
||||
if (P1point==2)
|
||||
score = "Thirty";
|
||||
if (P1point==3)
|
||||
score = "Forty";
|
||||
score += "-All";
|
||||
}
|
||||
if (P1point==P2point && P1point>3)
|
||||
score = "Deuce";
|
||||
|
||||
if (P1point > 0 && P2point==0)
|
||||
{
|
||||
if (P1point==1)
|
||||
P1res = "Fifteen";
|
||||
if (P1point==2)
|
||||
P1res = "Thirty";
|
||||
if (P1point==3)
|
||||
P1res = "Forty";
|
||||
|
||||
P2res = "Love";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
if (P2point > 0 && P1point==0)
|
||||
{
|
||||
if (P2point==1)
|
||||
P2res = "Fifteen";
|
||||
if (P2point==2)
|
||||
P2res = "Thirty";
|
||||
if (P2point==3)
|
||||
P2res = "Forty";
|
||||
|
||||
P1res = "Love";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
|
||||
if (P1point>P2point && P1point < 4)
|
||||
{
|
||||
if (P1point==2)
|
||||
P1res="Thirty";
|
||||
if (P1point==3)
|
||||
P1res="Forty";
|
||||
if (P2point==1)
|
||||
P2res="Fifteen";
|
||||
if (P2point==2)
|
||||
P2res="Thirty";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
if (P2point>P1point && P2point < 4)
|
||||
{
|
||||
if (P2point==2)
|
||||
P2res="Thirty";
|
||||
if (P2point==3)
|
||||
P2res="Forty";
|
||||
if (P1point==1)
|
||||
P1res="Fifteen";
|
||||
if (P1point==2)
|
||||
P1res="Thirty";
|
||||
score = P1res + "-" + P2res;
|
||||
}
|
||||
|
||||
if (P1point > P2point && P2point >= 3)
|
||||
{
|
||||
score = "Advantage player1";
|
||||
}
|
||||
|
||||
if (P2point > P1point && P1point >= 3)
|
||||
{
|
||||
score = "Advantage player2";
|
||||
}
|
||||
|
||||
if (P1point>=4 && P2point>=0 && (P1point-P2point)>=2)
|
||||
{
|
||||
score = "Win for player1";
|
||||
}
|
||||
if (P2point>=4 && P1point>=0 && (P2point-P1point)>=2)
|
||||
{
|
||||
score = "Win for player2";
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
public void SetP1Score(int number){
|
||||
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
P1Score();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetP2Score(int number){
|
||||
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
P2Score();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void P1Score(){
|
||||
P1point++;
|
||||
}
|
||||
|
||||
public void P2Score(){
|
||||
P2point++;
|
||||
}
|
||||
|
||||
public void WonPoint(string player) {
|
||||
if (player == "player1")
|
||||
P1Score();
|
||||
else
|
||||
P2Score();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,40 +2,40 @@ using System;
|
||||
|
||||
namespace Tennis
|
||||
{
|
||||
public class TennisGame3 : TennisGame
|
||||
{
|
||||
private int p2;
|
||||
private int p1;
|
||||
private string p1N;
|
||||
private string p2N;
|
||||
public class TennisGame3 : TennisGame
|
||||
{
|
||||
private int p2;
|
||||
private int p1;
|
||||
private string p1N;
|
||||
private string p2N;
|
||||
|
||||
public TennisGame3 (string player1Name, string player2Name)
|
||||
{
|
||||
this.p1N = player1Name;
|
||||
this.p2N = player2Name;
|
||||
}
|
||||
public TennisGame3 (string player1Name, string player2Name)
|
||||
{
|
||||
this.p1N = player1Name;
|
||||
this.p2N = player2Name;
|
||||
}
|
||||
|
||||
public string GetScore() {
|
||||
string s;
|
||||
if (p1 < 4 && p2 < 4) {
|
||||
string[] p = new String[]{"Love", "Fifteen", "Thirty", "Forty"};
|
||||
s = p[p1];
|
||||
return (p1 == p2) ? s + "-All" : s + "-" + p[p2];
|
||||
} else {
|
||||
if (p1 == p2)
|
||||
return "Deuce";
|
||||
s = p1 > p2 ? p1N : p2N;
|
||||
return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s;
|
||||
}
|
||||
}
|
||||
|
||||
public void WonPoint(string playerName) {
|
||||
if (playerName == "player1")
|
||||
this.p1 += 1;
|
||||
else
|
||||
this.p2 += 1;
|
||||
}
|
||||
public string GetScore() {
|
||||
string s;
|
||||
if (p1 < 4 && p2 < 4) {
|
||||
string[] p = new String[]{"Love", "Fifteen", "Thirty", "Forty"};
|
||||
s = p[p1];
|
||||
return (p1 == p2) ? s + "-All" : s + "-" + p[p2];
|
||||
} else {
|
||||
if (p1 == p2)
|
||||
return "Deuce";
|
||||
s = p1 > p2 ? p1N : p2N;
|
||||
return ((p1-p2)*(p1-p2) == 1) ? "Advantage " + s : "Win for " + s;
|
||||
}
|
||||
}
|
||||
|
||||
public void WonPoint(string playerName) {
|
||||
if (playerName == "player1")
|
||||
this.p1 += 1;
|
||||
else
|
||||
this.p2 += 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,113 +3,113 @@ using NUnit.Framework;
|
||||
|
||||
namespace Tennis
|
||||
{
|
||||
[TestFixture(0, 0, "Love-All")]
|
||||
[TestFixture( 1, 1, "Fifteen-All" )]
|
||||
[TestFixture( 2, 2, "Thirty-All")]
|
||||
[TestFixture( 3, 3, "Forty-All")]
|
||||
[TestFixture( 4, 4, "Deuce")]
|
||||
[TestFixture( 1, 0, "Fifteen-Love")]
|
||||
[TestFixture( 0, 1, "Love-Fifteen")]
|
||||
[TestFixture( 2, 0, "Thirty-Love")]
|
||||
[TestFixture( 0, 2, "Love-Thirty")]
|
||||
[TestFixture( 3, 0, "Forty-Love")]
|
||||
[TestFixture( 0, 3, "Love-Forty")]
|
||||
[TestFixture( 4, 0, "Win for player1")]
|
||||
[TestFixture( 0, 4, "Win for player2")]
|
||||
[TestFixture( 2, 1, "Thirty-Fifteen")]
|
||||
[TestFixture( 1, 2, "Fifteen-Thirty")]
|
||||
[TestFixture( 3, 1, "Forty-Fifteen")]
|
||||
[TestFixture( 1, 3, "Fifteen-Forty")]
|
||||
[TestFixture( 4, 1, "Win for player1")]
|
||||
[TestFixture( 1, 4, "Win for player2")]
|
||||
[TestFixture( 3, 2, "Forty-Thirty")]
|
||||
[TestFixture( 2, 3, "Thirty-Forty")]
|
||||
[TestFixture( 4, 2, "Win for player1")]
|
||||
[TestFixture( 2, 4, "Win for player2")]
|
||||
[TestFixture( 4, 3, "Advantage player1")]
|
||||
[TestFixture( 3, 4, "Advantage player2")]
|
||||
[TestFixture( 5, 4, "Advantage player1")]
|
||||
[TestFixture( 4, 5, "Advantage player2")]
|
||||
[TestFixture( 15, 14, "Advantage player1")]
|
||||
[TestFixture( 14, 15, "Advantage player2")]
|
||||
[TestFixture( 6, 4, "Win for player1")]
|
||||
[TestFixture( 4, 6, "Win for player2")]
|
||||
[TestFixture( 16, 14, "Win for player1")]
|
||||
[TestFixture( 14, 16, "Win for player2")]
|
||||
public class TennisTest
|
||||
{
|
||||
private int player1Score;
|
||||
private int player2Score;
|
||||
private string expectedScore;
|
||||
[TestFixture(0, 0, "Love-All")]
|
||||
[TestFixture( 1, 1, "Fifteen-All" )]
|
||||
[TestFixture( 2, 2, "Thirty-All")]
|
||||
[TestFixture( 3, 3, "Forty-All")]
|
||||
[TestFixture( 4, 4, "Deuce")]
|
||||
[TestFixture( 1, 0, "Fifteen-Love")]
|
||||
[TestFixture( 0, 1, "Love-Fifteen")]
|
||||
[TestFixture( 2, 0, "Thirty-Love")]
|
||||
[TestFixture( 0, 2, "Love-Thirty")]
|
||||
[TestFixture( 3, 0, "Forty-Love")]
|
||||
[TestFixture( 0, 3, "Love-Forty")]
|
||||
[TestFixture( 4, 0, "Win for player1")]
|
||||
[TestFixture( 0, 4, "Win for player2")]
|
||||
[TestFixture( 2, 1, "Thirty-Fifteen")]
|
||||
[TestFixture( 1, 2, "Fifteen-Thirty")]
|
||||
[TestFixture( 3, 1, "Forty-Fifteen")]
|
||||
[TestFixture( 1, 3, "Fifteen-Forty")]
|
||||
[TestFixture( 4, 1, "Win for player1")]
|
||||
[TestFixture( 1, 4, "Win for player2")]
|
||||
[TestFixture( 3, 2, "Forty-Thirty")]
|
||||
[TestFixture( 2, 3, "Thirty-Forty")]
|
||||
[TestFixture( 4, 2, "Win for player1")]
|
||||
[TestFixture( 2, 4, "Win for player2")]
|
||||
[TestFixture( 4, 3, "Advantage player1")]
|
||||
[TestFixture( 3, 4, "Advantage player2")]
|
||||
[TestFixture( 5, 4, "Advantage player1")]
|
||||
[TestFixture( 4, 5, "Advantage player2")]
|
||||
[TestFixture( 15, 14, "Advantage player1")]
|
||||
[TestFixture( 14, 15, "Advantage player2")]
|
||||
[TestFixture( 6, 4, "Win for player1")]
|
||||
[TestFixture( 4, 6, "Win for player2")]
|
||||
[TestFixture( 16, 14, "Win for player1")]
|
||||
[TestFixture( 14, 16, "Win for player2")]
|
||||
public class TennisTest
|
||||
{
|
||||
private int player1Score;
|
||||
private int player2Score;
|
||||
private string expectedScore;
|
||||
|
||||
public TennisTest(int player1Score, int player2Score, string expectedScore) {
|
||||
this.player1Score = player1Score;
|
||||
this.player2Score = player2Score;
|
||||
this.expectedScore = expectedScore;
|
||||
}
|
||||
public TennisTest(int player1Score, int player2Score, string expectedScore) {
|
||||
this.player1Score = player1Score;
|
||||
this.player2Score = player2Score;
|
||||
this.expectedScore = expectedScore;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void checkTennisGame1() {
|
||||
TennisGame1 game = new TennisGame1("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
[Test]
|
||||
public void checkTennisGame1() {
|
||||
TennisGame1 game = new TennisGame1("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void checkTennisGame2() {
|
||||
TennisGame2 game = new TennisGame2("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
[Test]
|
||||
public void checkTennisGame2() {
|
||||
TennisGame2 game = new TennisGame2("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void checkTennisGame3() {
|
||||
TennisGame3 game = new TennisGame3("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
[Test]
|
||||
public void checkTennisGame3() {
|
||||
TennisGame3 game = new TennisGame3("player1", "player2");
|
||||
checkAllScores(game);
|
||||
}
|
||||
|
||||
public void checkAllScores(TennisGame game) {
|
||||
int highestScore = Math.Max(this.player1Score, this.player2Score);
|
||||
for (int i = 0; i < highestScore; i++) {
|
||||
if (i < this.player1Score)
|
||||
game.WonPoint("player1");
|
||||
if (i < this.player2Score)
|
||||
game.WonPoint("player2");
|
||||
}
|
||||
Assert.AreEqual(this.expectedScore, game.GetScore());
|
||||
}
|
||||
public void checkAllScores(TennisGame game) {
|
||||
int highestScore = Math.Max(this.player1Score, this.player2Score);
|
||||
for (int i = 0; i < highestScore; i++) {
|
||||
if (i < this.player1Score)
|
||||
game.WonPoint("player1");
|
||||
if (i < this.player2Score)
|
||||
game.WonPoint("player2");
|
||||
}
|
||||
Assert.AreEqual(this.expectedScore, game.GetScore());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture()]
|
||||
public class ExampleGameTennisTest
|
||||
{
|
||||
public void RealisticTennisGame(TennisGame game)
|
||||
{
|
||||
String[] points = {"player1", "player1", "player2", "player2", "player1", "player1"};
|
||||
String[] expected_scores = {"Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1"};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
game.WonPoint(points[i]);
|
||||
Assert.AreEqual(expected_scores[i], game.GetScore());
|
||||
}
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame1()
|
||||
{
|
||||
TennisGame1 game = new TennisGame1("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame2()
|
||||
{
|
||||
TennisGame2 game = new TennisGame2("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame3()
|
||||
{
|
||||
TennisGame3 game = new TennisGame3("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
}
|
||||
[TestFixture()]
|
||||
public class ExampleGameTennisTest
|
||||
{
|
||||
public void RealisticTennisGame(TennisGame game)
|
||||
{
|
||||
String[] points = {"player1", "player1", "player2", "player2", "player1", "player1"};
|
||||
String[] expected_scores = {"Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-All", "Forty-Thirty", "Win for player1"};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
game.WonPoint(points[i]);
|
||||
Assert.AreEqual(expected_scores[i], game.GetScore());
|
||||
}
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame1()
|
||||
{
|
||||
TennisGame1 game = new TennisGame1("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame2()
|
||||
{
|
||||
TennisGame2 game = new TennisGame2("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
[Test()]
|
||||
public void CheckGame3()
|
||||
{
|
||||
TennisGame3 game = new TennisGame3("player1", "player2");
|
||||
RealisticTennisGame(game);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user