Blackjack Testing
One useful technique for this is to use the rand library function without calling the srand seeding function. There is a comment about this starting on line 24 of the rand_example.c program from Programming Assignment 3.
Another way to have repeatable tests is to "stack the deck" for a game of blackjack. That is, instead of running the program with a shuffled deck, you can use a deck that has a specific order of cards. In this way, you can repeatedly play the game and get the same results every time. You can also arrange the cards in an order that you can use to force certain outcomes of play.
An example of this is the deck of cards defined in the text file named sample-deck. There is a function that you can use to read a sample deck text file in read_deck.c
The blackjack program reads its playing commands from standard input. During normal play, these are typed at the terminal. For testing purposes, you can have a file of blackjack commands that can be redirected into the blackjack program, using the normal form of UNIX input redirection. For example, the set of commands that produces the sample output in the program writeup is in the file sample-commands
Finally, you can make reading a sample deck handy in the blackjack program by adding a command-line argument to the blackjack main function that optionally reads the deck from a text file. This would look something like this:
int main(int argc, char** argv) { ... if (argc == 2) { read_deck(deck, argv[1]); } ...
Putting all of this together, you can do a testing run of your blackjack program like this:
This testing run does the following:blackjack sample-deck < sample-commands > sample.out