fork(4) download
  1. /**
  2. * test.cpp
  3. *
  4. * <#Name#>
  5. * <#Uniqname#>
  6. *
  7. * EECS 183: Project 2
  8. *
  9. * Testing functions for your rps.cpp implementation.
  10. * Holds the definitions of required testing functions.
  11. * We have stubbed all required functions for you.
  12. */
  13.  
  14. #include <iostream>
  15. #include <string>
  16. using namespace std;
  17.  
  18. const int MAX_ROUNDS = 3;
  19.  
  20. void printInitialHeader();
  21.  
  22. /**
  23. * Requires: nothing
  24. * Modifies: cout
  25. * Effects: Prints the menu.
  26. * Prompts: "1) Play rock, paper, scissors"
  27. * "2) Play rock, paper, scissors, lizard, spock"
  28. * "3) Quit"
  29. * "Choice --> "
  30. */
  31. void printMenu();
  32.  
  33. /**
  34. * Requires: error_number be either 1 or 2
  35. * Modifies: cout
  36. * Effects: If error_number is 1, prints an error message indicating
  37. * an illegal name was entered.
  38. * If error_number is 2, prints an error message indicating
  39. * an illegal move was entered.
  40. */
  41. void printErrorMessage(int error_number);
  42.  
  43. /**
  44. * Requires: nothing
  45. * Modifies: cout
  46. * Effects: Prints out the final greeting for the program.
  47. */
  48. void printCloser();
  49.  
  50. //************************************************************************
  51. // You must implement all of the following functions. Add your
  52. // implementations below main as indicated.
  53. //************************************************************************
  54.  
  55. /**
  56. * Requires: player_number is either 1 or 2
  57. * Modifies: cout, cin
  58. * Effects: Prompts the user to enter their name. Names entered may
  59. * have spaces within them.
  60. * Example: "Kermit the frog"
  61. *
  62. * If an empty name is given, this is invalid input, so print
  63. * error message 1, and return a default name.
  64. * For player 1, the default name is: Rocky
  65. * For player 2, the default name is: Creed
  66. * Prompt: Player [player_number], enter your name:
  67. */
  68. string getName(int player_number);
  69.  
  70.  
  71. /**
  72. * Requires: nothing
  73. * Modifies: cout, cin
  74. * Effects: Prints the menu, and reads the input from the user.
  75. * Checks to make sure the input is within range for the menu.
  76. * If it is not, prints "Invalid menu choice". Continues to print
  77. * the menu and read in input until a valid choice is entered,
  78. * then returns the user's choice of menu options. You can assume
  79. * a user will enter an integer, and nothing else, as their choice.
  80. * Prompt: Invalid menu choice
  81. */
  82. int getMenuChoice();
  83.  
  84.  
  85.  
  86.  
  87. /**
  88. * Requires: nothing
  89. * Modifies: nothing
  90. * Effects: Returns true if and only if move represents a valid move character:
  91. * one of 'R', 'r', 'P', 'p', 'S', 's'. Returns false otherwise.
  92. */
  93. bool isMoveGood(char move);
  94.  
  95.  
  96.  
  97.  
  98. /**
  99. * Requires: player_name is the name of the player being prompted for their
  100. * move.
  101. * Modifies: cout, cin
  102. * Effects: Prompts the player for their move and returns it.
  103. * This function should accept the first non-whitespace character as
  104. * the move. If an illegal character is entered for their move, print
  105. * error message 2 and return rock as a default. You can assume a user
  106. * will enter a single character, and nothing else, as their move.
  107. * Prompt: [player_name], enter your move:
  108. */
  109. char getMove(string player_name);
  110.  
  111.  
  112.  
  113. /**
  114. * Requires: move is the move of the player being checked for a win.
  115. * opponent_move is the move of the opponent.
  116. * both move and opponent_move are valid moves.
  117. * Modifies: nothing
  118. * Effects: Returns true if and only if the player who made move won
  119. * according to the rules to rock-paper-scissors. Returns false
  120. * otherwise.
  121. */
  122. bool isRoundWinner(char move, char opponent_move);
  123.  
  124.  
  125.  
  126.  
  127. /**
  128. * Requires: winner_name is the name of the player who won the round.
  129. * Modifies: cout
  130. * Effects: If winner_name is empty, prints a message indicating the round
  131. * is a draw. Otherwise, prints a congratulatory message to the
  132. * winner.
  133. * Prompt: This round is a draw!
  134. * ------------- OR -------------
  135. * [winner_name] wins the round!
  136. */
  137. void announceRoundWinner(string winner_name);
  138.  
  139.  
  140.  
  141.  
  142. /**
  143. * Requires: p1_name and p2_name are the names of the respective players
  144. * Modifies: nothing
  145. * Effects: Simulates a complete round of rock-paper-scissors, which
  146. * consists of three steps:
  147. * 1. Get player1 move
  148. * 2. Get player2 move
  149. * 3. Return 0 if the round was a draw; 1 if player 1 won;
  150. * 2 if player 2 won.
  151. */
  152. int doRound(string p1_name, string p2_name);
  153.  
  154.  
  155.  
  156.  
  157. /**
  158. * Requires: winner_name is the name of the player who won the game.
  159. * Modifies: cout
  160. * Effects: If winner_name is blank, prints that the game was a draw.
  161. * Otherwise, prints a congratulatory message to the winner.
  162. * Prompt: No winner!
  163. * ------------- OR -------------
  164. * Congratulations [winner_name]!
  165. * You won EECS 183 Rock-Paper-Scissors!
  166. */
  167. void announceWinner(string winner_name);
  168.  
  169.  
  170.  
  171.  
  172. /**
  173. * Requires: p1_name and p2_name are the names of the respective players,
  174. * game_type can be 1 for regular rock-paper-scissors
  175. * or 2 for rock-paper-scissors-lizard-spock
  176. * Modifies: cout
  177. *
  178. * Base Project:
  179. * Effects: If game_type is 2, prints "Under Construction" to indicate that the
  180. * s'more has not been implemented. Returns empty string.
  181. * Otherwise, plays exactly three rounds of rock-paper-scissors while
  182. * keeping track of the number of round wins for each player.
  183. * When a round results in a draw, neither player is the winner,
  184. * so neither player is awarded a point.
  185. * After each round is played, the round winner (or draw) is
  186. * announced. Returns the name of the winner or an empty string if the
  187. * game ended in a draw.
  188. * Prompt: Under Construction
  189. *
  190. * S'more Version:
  191. * Effects: Has same functionality as base project, but also handles a
  192. * game_type of 2. When game_type is 2, plays exactly three rounds of
  193. * rock-paper-scissors-lizard-spock. Keeps track of round wins for
  194. * each player and announces round winners in the same fashion as
  195. * described above.
  196. */
  197. string doGame(string p1_name, string p2_name, int game_type);
  198.  
  199. //************************************************************************
  200. // You should have implemented the following functions in rps.cpp
  201. //************************************************************************
  202.  
  203. bool isMoveGood(char move);
  204. bool isRoundWinner(char move, char opponent_move);
  205. void announceRoundWinner(string winner_name);
  206. void announceWinner(string winner_name);
  207.  
  208. //************************************************************************
  209. // Function declarations. Function definition is below main.
  210. //************************************************************************
  211.  
  212. void test_isMoveGood();
  213. void test_isRoundWinner();
  214. void test_announceRoundWinner();
  215. void test_announceWinner();
  216.  
  217.  
  218. int main() {
  219. // TODO: call test functions here
  220. test_isMoveGood();
  221. test_announceWinner();
  222. test_announceRoundWinner();
  223. test_announceWinner();
  224.  
  225. return 0;
  226. }
  227.  
  228. //************************************************************************
  229. // Put all your test function implementations below here.
  230. // We have stubbed all required functions for you
  231. // to recieve full points when submitting test.cpp
  232. //************************************************************************
  233.  
  234. void test_isMoveGood() {
  235. // TODO: implement
  236. //Testing for Valid Moves
  237.  
  238. for (int i = 0; i<26; i++)
  239. {
  240. cout << isMoveGood(i + 'a') << endl;
  241. cout << isMoveGood(i + 'A') << endl;
  242. }
  243. }
  244.  
  245. void test_isRoundWinner() {
  246. // TODO: implement
  247.  
  248. char moves[6] = { 'R','r','S','s','P','p' };
  249.  
  250. for (int i = 0; i<6; i++)
  251. {
  252. for (int j = 0; j<6; j++)
  253. {
  254. cout << isRoundWinner(moves[i], moves[j]) << endl;
  255. }
  256. }
  257. }
  258.  
  259. void test_announceRoundWinner() {
  260. // TODO: implement
  261.  
  262. announceRoundWinner("xyz abc");
  263. announceRoundWinner("Rana Tigrina");
  264. announceRoundWinner("David Rocco") ;
  265. announceRoundWinner("Yo Yo Yo Yo Yo") ;
  266. announceRoundWinner("why are you doing this") ;
  267. announceRoundWinner("") ;
  268. announceRoundWinner("A");
  269. }
  270.  
  271. void test_announceWinner() {
  272. // TODO: implement
  273.  
  274. announceWinner("xyz abc") ;
  275. announceWinner("David Rocco");
  276. announceWinner("Rana Tigrina") ;
  277. announceWinner("Ho Ho Ho Ho Ho") ;
  278. announceWinner("This is so Boooooring :(") ;
  279. announceWinner("Z") ;
  280. announceWinner("") ;
  281. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/ijviaJ/ccAEeBxC.o: In function `test_isMoveGood()':
prog.cpp:(.text+0x38): undefined reference to `isMoveGood(char)'
prog.cpp:(.text+0x93): undefined reference to `isMoveGood(char)'
/home/ijviaJ/ccAEeBxC.o: In function `test_isRoundWinner()':
prog.cpp:(.text+0x1bc): undefined reference to `isRoundWinner(char, char)'
/home/ijviaJ/ccAEeBxC.o: In function `test_announceRoundWinner()':
prog.cpp:(.text+0x28b): undefined reference to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x2d3): undefined reference to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x321): undefined reference to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x372): undefined reference to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x3fb): undefined reference to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/ijviaJ/ccAEeBxC.o:prog.cpp:(.text+0x42d): more undefined references to `announceRoundWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' follow
/home/ijviaJ/ccAEeBxC.o: In function `test_announceWinner()':
prog.cpp:(.text+0x4eb): undefined reference to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x539): undefined reference to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x581): undefined reference to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x5d2): undefined reference to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
prog.cpp:(.text+0x659): undefined reference to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/ijviaJ/ccAEeBxC.o:prog.cpp:(.text+0x690): more undefined references to `announceWinner(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' follow
collect2: error: ld returned 1 exit status
stdout
Standard output is empty