Homework is important practice for you, but it’s not graded so you don’t have to submit it.
For this second homework assignment you will develop a basic test
framework for the
wc program from Homework 1.
This involves some simple shell scripting which may seem scary at
first (“Yet another language, are you serious?”), but you are free
to base your own script on the examples posted on Piazza.
You will also have to work up some actual test cases. For now we’re doing simple input-output testing, so you just have to try to come up with a variety of “challenging” inputs and what the corresponding outputs should be. (There are some hints about this below.)
Homework 1 required a very simple
Makefile that just sets the
compiler options using the
For this homework assignment, your
Makefile should support all
of the following:
makewithout an explicit target should build the
make cleanshould remove the
wcprogram and any other derived files (a “derived file” is one that can be rebuilt from the remaining files; so
wcis a derived file since the compiler can rebuild it from
make testshould (if necessary) build the
wcprogram first and then run all the test cases using a shell script
You should also have a shell script
testwc.sh that will run the
test cases. As discussed in lecture, the script should make no output
whatsoever if all test cases pass; for test cases that fail, the
script should give some indication of which test case failed and
how it failed. (The latter is not too difficult, see the example
shell script posted on Piazza.)
For the actual test cases, please follow the naming convention we
used in lecture:
something.in contains the input for a test case,
something.out contains the expected output.
wcprogram counts “words” correctly; this implies testing that the actual definition of “word” from the
wcman page has been implemented correctly.
LINEFEEDcharacter; if you’re working on Windows, you may run into the problem that two characters,
CARRIAGE RETURN, are used instead. If in doubt, develop your test cases for UNIX and not Windows.
NULcharacters (meaning ten zero-bytes) should produce as an answer from
wc. (Or think of a
wccommand does for your test cases. In fact, you probably should. You might make a surprising discovery…
It can be hard to figure out when you have “enough” test cases. We’ll chat about a few heuristics (“rules of thumb”) for this in lecture, but there are also slightly more “objective” approaches. You may want to look up the terms “code coverage” (and “line coverage” in particular) to get an idea of what we’d like to do. Hopefully we’ll find the time to “cover” (hah!) coverage analysis in lecture soon.