From 91630a3a3482e211252efe2b784442126fb92463 Mon Sep 17 00:00:00 2001 From: emilybache Date: Mon, 10 Dec 2012 14:35:09 +0100 Subject: [PATCH] convert tabs to spaces --- Tennis/cpp/defactored1/Tennis.cc | 114 ++++++++++---------- Tennis/cpp/defactored2/Tennis.cc | 172 +++++++++++++++---------------- Tennis/cpp/defactored3/Tennis.cc | 22 ++-- 3 files changed, 154 insertions(+), 154 deletions(-) diff --git a/Tennis/cpp/defactored1/Tennis.cc b/Tennis/cpp/defactored1/Tennis.cc index eeac646d..0f340f5f 100644 --- a/Tennis/cpp/defactored1/Tennis.cc +++ b/Tennis/cpp/defactored1/Tennis.cc @@ -1,63 +1,63 @@ #include const std::string tennis_score(int p1Score, int p2Score) { - std::string score = ""; - int tempScore=0; - if (p1Score==p2Score) - { - switch (p1Score) - { - case 0: - score = "Love-All"; - break; - case 1: - score = "Fifteen-All"; - break; - case 2: - score = "Thirty-All"; - break; - case 3: - score = "Deuce"; - break; - default: - score = "Deuce"; - break; - - } - } - else if (p1Score>=4 || p2Score>=4) - { - int minusResult = p1Score-p2Score; - 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 = p1Score; - else { score+="-"; tempScore = p2Score;} - switch(tempScore) - { - case 0: - score+="Love"; - break; - case 1: - score+="Fifteen"; - break; - case 2: - score+="Thirty"; - break; - case 3: - score+="Forty"; - break; - } - } - } - return score; - + std::string score = ""; + int tempScore=0; + if (p1Score==p2Score) + { + switch (p1Score) + { + case 0: + score = "Love-All"; + break; + case 1: + score = "Fifteen-All"; + break; + case 2: + score = "Thirty-All"; + break; + case 3: + score = "Deuce"; + break; + default: + score = "Deuce"; + break; + + } + } + else if (p1Score>=4 || p2Score>=4) + { + int minusResult = p1Score-p2Score; + 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 = p1Score; + else { score+="-"; tempScore = p2Score;} + switch(tempScore) + { + case 0: + score+="Love"; + break; + case 1: + score+="Fifteen"; + break; + case 2: + score+="Thirty"; + break; + case 3: + score+="Forty"; + break; + } + } + } + return score; + } TEST(TennisTest, LoveAll_0_0) { diff --git a/Tennis/cpp/defactored2/Tennis.cc b/Tennis/cpp/defactored2/Tennis.cc index 5f193038..8ff36536 100644 --- a/Tennis/cpp/defactored2/Tennis.cc +++ b/Tennis/cpp/defactored2/Tennis.cc @@ -1,94 +1,94 @@ #include const std::string tennis_score(int p1Score, int p2Score) { - std::string score = ""; + std::string score = ""; std::string P1res = ""; std::string P2res = ""; - if (p1Score == p2Score && p1Score < 4) - { - if (p1Score==0) - score = "Love"; - if (p1Score==1) - score = "Fifteen"; - if (p1Score==2) - score = "Thirty"; - if (p1Score==3) - score = "Forty"; - score += "-All"; - } - if (p1Score==p2Score && p1Score>2) - score = "Deuce"; - - if (p1Score > 0 && p2Score==0) - { - if (p1Score==1) - P1res = "Fifteen"; - if (p1Score==2) - P1res = "Thirty"; - if (p1Score==3) - P1res = "Forty"; - - P2res = "Love"; - score = P1res + "-" + P2res; - } - if (p2Score > 0 && p1Score==0) - { - if (p2Score==1) - P2res = "Fifteen"; - if (p2Score==2) - P2res = "Thirty"; - if (p2Score==3) - P2res = "Forty"; - - P1res = "Love"; - score = P1res + "-" + P2res; - } - - if (p1Score>p2Score && p1Score < 4) - { - if (p1Score==2) - P1res="Thirty"; - if (p1Score==3) - P1res="Forty"; - if (p2Score==1) - P2res="Fifteen"; - if (p2Score==2) - P2res="Thirty"; - score = P1res + "-" + P2res; - } - if (p2Score>p1Score && p2Score < 4) - { - if (p2Score==2) - P2res="Thirty"; - if (p2Score==3) - P2res="Forty"; - if (p1Score==1) - P1res="Fifteen"; - if (p1Score==2) - P1res="Thirty"; - score = P1res + "-" + P2res; - } - - if (p1Score > p2Score && p2Score >= 3) - { - score = "Advantage player1"; - } - - if (p2Score > p1Score && p1Score >= 3) - { - score = "Advantage player2"; - } - - if (p1Score>=4 && p2Score>=0 && (p1Score-p2Score)>=2) - { - score = "Win for player1"; - } - if (p2Score>=4 && p1Score>=0 && (p2Score-p1Score)>=2) - { - score = "Win for player2"; - } - return score; - + if (p1Score == p2Score && p1Score < 4) + { + if (p1Score==0) + score = "Love"; + if (p1Score==1) + score = "Fifteen"; + if (p1Score==2) + score = "Thirty"; + if (p1Score==3) + score = "Forty"; + score += "-All"; + } + if (p1Score==p2Score && p1Score>2) + score = "Deuce"; + + if (p1Score > 0 && p2Score==0) + { + if (p1Score==1) + P1res = "Fifteen"; + if (p1Score==2) + P1res = "Thirty"; + if (p1Score==3) + P1res = "Forty"; + + P2res = "Love"; + score = P1res + "-" + P2res; + } + if (p2Score > 0 && p1Score==0) + { + if (p2Score==1) + P2res = "Fifteen"; + if (p2Score==2) + P2res = "Thirty"; + if (p2Score==3) + P2res = "Forty"; + + P1res = "Love"; + score = P1res + "-" + P2res; + } + + if (p1Score>p2Score && p1Score < 4) + { + if (p1Score==2) + P1res="Thirty"; + if (p1Score==3) + P1res="Forty"; + if (p2Score==1) + P2res="Fifteen"; + if (p2Score==2) + P2res="Thirty"; + score = P1res + "-" + P2res; + } + if (p2Score>p1Score && p2Score < 4) + { + if (p2Score==2) + P2res="Thirty"; + if (p2Score==3) + P2res="Forty"; + if (p1Score==1) + P1res="Fifteen"; + if (p1Score==2) + P1res="Thirty"; + score = P1res + "-" + P2res; + } + + if (p1Score > p2Score && p2Score >= 3) + { + score = "Advantage player1"; + } + + if (p2Score > p1Score && p1Score >= 3) + { + score = "Advantage player2"; + } + + if (p1Score>=4 && p2Score>=0 && (p1Score-p2Score)>=2) + { + score = "Win for player1"; + } + if (p2Score>=4 && p1Score>=0 && (p2Score-p1Score)>=2) + { + score = "Win for player2"; + } + return score; + } TEST(TennisTest, LoveAll_0_0) { diff --git a/Tennis/cpp/defactored3/Tennis.cc b/Tennis/cpp/defactored3/Tennis.cc index cb2fae89..4cce3d6a 100644 --- a/Tennis/cpp/defactored3/Tennis.cc +++ b/Tennis/cpp/defactored3/Tennis.cc @@ -1,19 +1,19 @@ #include const std::string tennis_score(int p1, int p2) { - std::string s; + std::string s; std::string p1N = "player1"; std::string p2N = "player2"; - if (p1 < 4 && p2 < 4 && !(p1 == 3 && p2 == 3)) { - std::string p[4] = {"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; - } + if (p1 < 4 && p2 < 4 && !(p1 == 3 && p2 == 3)) { + std::string p[4] = {"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; + } } TEST(TennisTest, LoveAll_0_0) {