CS35: Data Structures and Algorithms

Lab 03 Notes

Lab 03 Agenda

Clone lab03

This is the same as lab02. Remember to run ssh-add when you log in, so you don't get repeatedly asked for you ssh password. Go to the CS35 github org, to find the clone link for your repo on the web interface.
$ cd ~/cs35/labs
$ git clone <link you got from github> ./lab03
You should also update your examples repository by going in your examples directory and pulling the updated version of the repository
$ cd ~/cs35/examples/
$ git pull

Setup Symbolic Link

Part of Lab 03 will ask you to experimentally time some mystery functions. Set up the symbolic link to the function timer using the commands below:
$ cd ~/cs35/labs/lab03
[lab03]$ ln -s /usr/local/bin/function_timer_f17 ./function_timer

Quicksort Algorithm Description

You will be asked in Lab to implement and test in C++ the pseudocode description of the Quicksort Algorithm

Writing in $\LaTeX$

Part of Lab 03 asks you to submit a PDF with typewritten solution to some problems. One way of typesetting mathematical formulas is to use to $\LaTeX$. Rather than providing a full explanation of $\LaTeX$, we have provided a number of example files. LearningLaTeX.tex and WrittenLab.tex are in your lab03 folder. bigO.tex is in your examples/week-04 folder. You can edit .tex files with a the same editor you use to edit C++ code. To build a PDF from a .tex file, use the command pdflatex, e.g.,
[lab03]$ pdflatex WrittenLab.tex
[lab03]$ evince WrittenLab.pdf
You are encouraged, but not required to use the WrittenLab.tex template to complete your written portion of the lab. You are required to submit your typeset work as a PDF.

Unit Testing

Part of your lab will ask you to test your quicksort implementation by writing and testing using a Unit Testing framework. Unit tests allow you to write numerous small tests that check that your code works as expected. By writing a variety of unit tests, you can identify bugs in your program early and fix logic errors as the unit tests uncover them. We will be using a unit test framework called UnitTest++ that is fairly easy to pick up and use in CS35.

Include the UnitTest++ header files in your test program

#include <UnitTest++/UnitTest++.h>

Each test is defined by giving the test a name and placing the name in the TEST(), e.g.,

TEST(myTest){
  /* write your test here */
}

This week you will mostly be using the CHECK_EQUAL macro to test the correctness of your program. CHECK_EQUAL(a,b) will check if a == b. If it does, the test will continue. If a check fails, the test will fail with an error message saying which test failed, what the expected values were, and what line number had the failing test.

You can write as many tests as you like, though Lab 03 requires you to write at least four more. Instead of calling the tests individually in main(), the following code will call all the tests you defined.

return UnitTest::RunAllTests();
An overview of available macros and tests is available at the UnitTest++ Macro Reference

Lab 03

That's it for in lab exercises. Hop over to the Lab 03 Writeup to begin the lab.