EECS 183 Labs

EECS 183 Lab 8: Testing

Lab due on your scheduled lab day (Mar 28 - Apr 1)

Lab accepted for full credit until Monday, April 4, 2022, 11:59 pm Eastern

In this lab, you are creating test cases for the Elevators final project, and learning about testing with classes.

Starter Files

The starter files for the lab are the Elevators project starter files.

You will submit your test.cpp from the Elevators project for grading.

IMPORTANT: For this lab, you will use your Visual Studio or Xcode project that you create for the final project. If you have not yet download the starter code and created a project, do so first -

Lab Assignment

Tasks to Complete

  1. If you have not already done so yet, start a new project with your IDE using the starter files for the Elevators final project.
  2. If you have not already done so yet, copy the test cases for the Person class from the specification.
  3. Create more test cases for Person class functions:
    • Person::Person() - non-default constructor
    • Person::tick()
  4. Create test cases for the Elevator class functions:
    • Elevator::tick()
    • Elevator::serviceRequest()
  5. Sumbit your test cases to the autograder
  6. Check your Visual Studio or Xcode project to make sure your text files, like and, are in the correct folder for your project. This task is not graded for the lab but will be essential for you to complete the Core and the Reach for Elevators.

Getting Started with test.cpp

You are able to submit test.cpp with tests for any of the functions in the project. The lab autograder will only grade the tests for the functions listed above

First, you will need to download the Elevators final project starter files and create a project using Visual Studio or Xcode.

NOTE: If you have already started the final project you do not need to do this step again! Use the VS/Xcode project and test.cpp from the final project for the lab.

Next, copy the example tests below and paste into the test.cpp file of your project. This is the same test example found in the Testing secion of the Elevators specification.

// declare your test functions here
void person_tests();

void start_tests() {
    // call your test functions here


// write test functions here
void person_tests() {
    //initialize a person with targetFloor 5, anger 5
    Person p("0f0t5a5");
    cout << p.getTargetFloor() << " " << p.getAngerLevel() << " Expected 5 5" << endl;

    //simulate time being a multiple of TICKS_PER_ANGER_INCREASE
    bool exploded = p.tick(TICKS_PER_ANGER_INCREASE);
    cout << exploded << " Expected 0" << endl;
    cout << p.getTargetFloor() << " " << p.getAngerLevel() << " Expected 5 6" << endl;

    //simulate time not being a multiple

    //no change
    cout << p.getTargetFloor() << " " << p.getAngerLevel() << " Expected 5 6" << endl;

    p.tick(TICKS_PER_ANGER_INCREASE); //7 after
    p.tick(TICKS_PER_ANGER_INCREASE); //8 after
    p.tick(TICKS_PER_ANGER_INCREASE); //9 after
    exploded = p.tick(TICKS_PER_ANGER_INCREASE);
    cout << exploded << " Expected 1" << endl;


IMPORTANT: Compile and run your project to make sure that there are no errors before moving on!

Once your test cases compile and run, submit your test.cpp to the autograder. The above tests should find two of the autograder bugs:

Note: ctor is an abbreviation for constructor. If your sumbission does not expose these bugs, repeat the setup and try again.

Once you have successfully added the above test cases, start creating more tests for the Person and Elevator classes.

Person Class

You will need to create more test cases for the functions Person::Person() - non-default constructor, and Person::tick()

NOTE: For your test cases, there is also a Person::print() function that you can use to print the values of a Person variable. _It is not implemented - you will have to implement ``Person::print()` to use in in your tests.

 * Requires: nothing
 * Modifies: outs
 * Effects:  Prints the infoString of the person NOT including the turn
 * Example:  Person p("7f4t8a3");
 *           cout << "\nThe person you just entered is: ";
 *           p.print(cout);
 *           This will print "f4t8a3"
void print(ostream &outs);

Note: For Person class variables, you can use multiple statements like the following to print a Person variable using cout.

// both of these test cases require implementing Person::print() first!
Person sal("0f0t5a5");
cout << endl;

Person pal("0f0t5a5");
cout << pal << endl;

Elevator Class

You will need to create test cases for the functions Elevator::tick() and Elevator::serviceRequest().

NOTE: You cannot use the overloaded operator to print an Elevator. However, there is an Elevator::print() function which has already been implemented for you.

Here is an example of an Elevator test case for the default constructor, to get you started.

void elevator_tests() {

    // NOTE - there is an Elevator::print function!

    // this will not find any of the bugs for the lab assignment
    Elevator e1;

Do not forget the function declaration before start_tests() void elevator_tests();, and to call elevator_tests(); in start_tests()

// declare your test functions here
void person_tests();
void elevator_tests();
void start_tests() {
    // call your test functions here


File IO and Project Setup

It is imperative that your Xcode/Visual studio project is set up correctly to read and write text files. Be sure to edit the scheme for Xcode and that the files are in the correct directory in Visual Studio.

Here is a test case that you can add to your test.cpp to check if your text files, like and, are in the correct directory. Be sure to call file_check in your start_tests function!

void file_check() {

    // open one of the text files that are part of the starter code
    ifstream ins;"");

    // if the file was not in the correct directory, the stream state is fail
    if ( {
        cout << "Could not open" << endl;
    else {
        cout << "Success! Text files are in the right directory." << endl;


If you get the message "Could not open" try editing the scheme again or checking that you have the project files in the correct directory.

If you cannot get the text files in the correct directory, then try adding the following to your file_check test.

// if the file is not in the right directory, try this:
ofstream outs;"crazyfilename");
outs << "find the file named crazyfilename in windows explorer or finder";

Then open Windows Explorer (Windows) or Finder (Mac) and search for the file named crazyfilename. Once you find the folder with that file name, copy all of the .in files from the project starter files to the same directory. Then try the file_check test again.

How to Submit

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