Chapter 13 Exercise Set 0: Chapter Review¶
Create a directory named
Cardsand downloadsrc.tgzinto this directory. Run:tar xzvf src.tgz
in the unix command shell to extract the directory containing the following source files:
Cards.hCards.cpprandom.hrandom.cpptest_random.cpptest_cards.cpptest_decks.cpp
You can remove the
.tgzfile after extracting it.Add a file named
Makefilein theCardsdirectory (along side thesrcsubdirectory) with the following contents:CC=g++ STD=c++11 build/%.o: src/%.cpp @mkdir -p build @$(CC) -MM -MT $@ $< > build/$*.d $(CC) -c -o $@ $< -std=$(STD) build/test_random: build/test_random.o build/random.o $(CC) -o $@ $^ -std=$(STD) build/test_cards: build/test_cards.o build/random.o build/Cards.o $(CC) -o $@ $^ -std=$(STD) build/test_decks: build/test_decks.o build/random.o build/Cards.o $(CC) -o $@ $^ -std=$(STD) -include build/*.d .PHONY: test all clean test_random: build/test_random ./build/test_random test_cards: build/test_cards ./build/test_cards test_decks: build/test_decks ./build/test_decks test: test_random test_cards test_decks clean: rm -rf build
Assuming you have Make installed on your system, you should now be able to run the following commands:
- make test_random - make test_cards - make test_decks - make test - make clean
Try each of these to see what they do.
Take a look at the tests in
test_random.cpp. How do they “test” that the function behaves as desired? Can you think of any possible problems with the approach taken?