EECS 183 Labs

EECS 183 Lab 4: Testing and Functions

Lab due on your scheduled lab day (September 17 - September 23)

Lab accepted for full credit until Tuesday, September 24, 2024, 11:59 pm Eastern

You must complete both part 1 and part 2 to be able to recevie full credit for the lab.

In this lab, you are writing code and solving practice exam questions to master the use of conditionals and prepare for the first exam. The main focus of the lab exercise is how to use (call) and test functions. You will have a lot of practice writing the definitions for functions in Project 2. While completing this lab, you will learn the testing tools necessary to master Project 2.

By completing this lab assignment, you will learn:

For all labs in EECS 183, to receive a grade, every student must individually submit the lab assignment, even if you are working in a group.

Starter Files

You can download the starter files using this link.

The IDE setup tutorials for Visual Studio and XCode include a video about how to set up a project using the starter files. You can access the tutorials here:

Lab Assignment Part 1 - lab4.cpp

NOTE: The test cases you create in this lab can and should be used for your Project 2 tests. Specifically, the tests you create in this lab should be added to your test.cpp. While Project 2 is an individual assignment, the test cases you create with your lab team can be submitted for credit.

Function to test: isMoveGood()

IMPORTANT: Note that for this project you can assume user input will always be of the data type expected (which is char for moves). In other words, as the programmer, you only need to check that values entered are valid moves - you do not need to worry about users entering integers, doubles, strings, bools, or any combination of these. Those are bad inputs and are prohibited by the REQUIRES clause.

/**
 * Requires: nothing
 * Modifies: nothing
 * Effects:  Returns true if and only if move represents a valid move character:
 *           one of 'R', 'r', 'P', 'p', 'S', 's'. Returns false otherwise.
 */
bool isMoveGood(char move);

Function to write: test_isMoveGood()

IMPORTANT: Since isMoveGood() returns a value of type bool, this will print a 0 for false and a 1 for true.

void test_isMoveGood() {
    cout << "Now testing function isMoveGood()\n";
    cout << "'r': Expected: 1, Actual: " << isMoveGood('r') << endl;

    // TODO: implement more test cases here

    return;
}
void test_isMoveGood() {
    cout << "Now testing function isMoveGood()\n";

    if (!isMoveGood('r')) {
        cout << "FAILED: isMoveGood('r') should have returned 'true'" << endl;
    }

    // etc.

    return;
}

Function to test: annouceRoundWinner()

/**
 * Requires: winnerName is the name of the player who won the round.
 * Modifies: cout
 * Effects:  If winnerName is empty, print a message indicating the round
 *           is a draw. Otherwise, print a congratulatory message to the
 *           winner.
 * Prompt:   This round is a draw!
 *           ------------- OR -------------
 *           [winner_name] wins the round!
 */
void announceRoundWinner(string winnerName);

Function to write: test_annouceRoundWinner()

IMPORTANT: Since announceRoundWinner() has a return type of void, you cannot print the non-existent return value from calling the function!.

Bugs To Expose

There are a total of 4 unique bugs to find in our implementations of isMoveGood() and announceRoundWinner(). Your tests will need to expose all of the bugs to receive full points for the lab. The autograder will tell you the names of the bugs that you have exposed, from the following set:

How to Submit

Note: If you’re using Xcode and don’t know how where exactly lab4.cpp is located on your disk, right-click (or click while holding down the Control key) on the file in the Navigator area on the left side of the Xcode window and choose Show in Finder.

If you’re using Visual Studio and would like to know where lab4.cpp is on your disk, right-click on lab4.cpp in the tab above the Code pane and choose Open Containing Folder.

IMPORTANT: For all labs in EECS 183, to receive a grade, every student must individually submit the lab. Late submissions for labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.

Lab Assignment Part 2 - RME Canvas Quiz

RMEs

RMEs (Requires, Modifies, Effects) are the comments that appear above function declarations for labs and projects. They document what a programmer needs to know to be able to call a function. These comments also contain essential information needed to write the function definitions for labs and projects.

  1. Take a few minutes to review the slides on RME’s here.
  2. Complete the Canvas quiz Lab 4 - RME Quiz.. You have an unlimited number of attempts for the quiz but must complete it by the date at the top of this document.