EECS 183 Labs

EECS 183 Lab 3: Testing and Functions

Lab due on your scheduled lab day

Lab accepted for full credit until Monday, February 7, 2022, 11:59 pm Eastern

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 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 assingment, 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

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 input and 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, prints a message indicating the round
 *           is a draw. Otherwise, prints 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 lab3.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 lab3.cpp is on your disk, right-click on lab3.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 submission for labs will not be accepted for credit. For this lab, you will receive ten submissions per day with feedback.