Design of mini2.erl

This was my first solution. My idea was to use tuples to represent the contents of the refrigerator. In particular a tuple of the form {Food, N} represents N items of type Food in the refrigerator. For example, {5, turnip} would mean I had five turnips in the refrigerator. Adding new items involved searching for a tuple with the right type of food, and increasing its count. If no such tuple was in the FoodList, I'd add a new tuple. Deleting also involved searching the list, but there were special cases for when the count went to zero (delete the tuple) or negative (report 'not_enough'). When I finished, I thought, this is too complicated for what is supposed to be an introductory problem.

Design of mini2b_stubs.erl

After finishing the first version, I realized that doing the arithmetic and checking for results of zero or negative was adding a lot of the complexity. I decided to go back to the representation from Learn You Some Erlang, I'd just use a list of atoms. If there are five turnips in the refrigerator, then there will be five occurrences of the atom 'turnip' in FoodList. While this won't be as efficient with memory if you put millions of turnips into your refrigerator, it should work fine for an introductory problem. I tried this, and the code si much simpler. That's the version sketched in mini2b_stubs.erl.

Testing

I wrote a set of test cases, see mini2_test.erl. I've tried these with both of my solutions to the mini assignment, and they both pass all of the tests. While this isn't surprising -- I wrote both the solutions and the tests -- it gives me some hope that these tests should work well with other solutions as well, including yours.

I found that it's handy to be able to run the tests with any output from the the code actually being printed. In particular, this let me put io:format statements in my code to trace the interaction between the different processes. Yeah, it's debugging with printf statements, but it got the job done. The standard EUnit interface suppresses output from the code under test. So, I wrote function try_it/0, try_it/1, and try_it/2 at the end of mini2_test.erl that let you run sets of tests on particular refrigerators with the output displayed. I found I could debug pretty quickly once I had that.