Lab 4
Covering our Bases


Preliminary Setup

  1. Create a new PyCharm project. Remember to use your last name in the project name.
  2. Download the starter code:
  3. Please replace ??????? with your name in the :author: tag in

Have a look around

Now that you have a project and some code, explore to see what you have:
  1. Skim the code in Notice that some functions are marked as private (their names start with two underscores). What functions are public and which are private?
  2. Use the debugger to determine what internal representation is being used to store a tictactoe board:
    1. Set a breakpoint at the beginning of create in
    2. Run in the debugger.
    3. Step to see how create sets up the board.
    4. What is the internal representation of the board?
    5. Create a file called internal_rep.txt and write a short description of the internal representation of a board.
  3. Take a look at Notice the Information Hiding:

Look at some tests

Take a look at, which uses the helper functions in to test tictactoe_board.get_winner(). There are three tests in our test suite (i.e. set of tests), and for each test we have:

Notice that the board we pass to get_winner() is hard-coded in each of the tests. In regular code, you would not want to hard-code what could be computed, but in testing code, you want to hard-code:

Add some tests

Your job is to add additional tests for get_winner(). Are there situations the existing tests don't cover? Try to be thorough. One way to think about how to be thorough is to think about coverage. We say that a test "covers" a line of code if running that test causes that line of code to be executed. For a test suite, we say that the test suite covers a line of code if there's at least one test case in the test suite that covers the line of code.

How to turn in this lab

Before turning in any program in this class, remember this mantra:

Just because it works doesn't mean it's good.

Part of your grade will also come from things like how understandable and readable your code is. You will also be graded on the neatness, presentation, and style of your program code.

For all labs, turn in only an electronic version. Please compress your program and email the zip file or tarball to me at

Ask for help if you're having problems!