CS 257: Software Design

Books, Phase 2: unit tests

Folder name: books

Work with the same partner(s) you worked with for Phase 1.

Relevant files

For your convenience, here are the files you'll need for this assignment.

Goals

Test-driven development

The purpose of Phases 2 and 3 of the Books assignment is to give you an introduction to test-driven development (TDD). Roughly, the process goes like this:

For us, the class will be called BooksDataSource, and its purpose will be to provide Python programmers with convenient access to the data in our books dataset.

The trick to writing good unit test suites is to think deeply about the many ways your interfaces might be called. Your tests should, for example, test typical cases, weird cases, and illegal cases. (For a really simple example, a unit test suite for a square-root function ought to include attempts to compute the square-roots of positive integers, positive non-integers, negative numbers, and zero, and depending on the language and the completeness of the interface specification, maybe non-numerical input.) You should think hard about the mistakes programmers can make, but also about the ways malicious programmers might try to exploit errors or omissions in your code.

Your job for Phase 2

IMPORTANT: During Phase 2, you may not change BooksDataSource in any way. (The graders and I will test this by using the Unix command diff, by the way.) In Phase 3, you will implement the methods in the BooksDataSource class, during which process you may add new methods to BooksDataSource if you wish, but you may not change BooksDataSource's original method signatures during either Phase 2 or Phase 3.

The data files

Take a look at the description of the data files in the comment to the __init__ method in booksdatasource.py. You'll see that I have separated out the books and authors into three (yes, three) CSV files: books.csv, authors.csv, and books_authors.csv. This structure gives each book and ID number, each author an ID number, and provides a more consistent and generalizable way of connecting books to authors. Here's a snippet of each file to give you the idea:

books.csv: 41,Middlemarch,1871 6,Good Omens,1990 ... authors.csv: 5,Gaiman,Neil,1960,NULL 6,Pratchett,Terry,1948,2015 22,Eliot,George,1819,1880 ... books_authors.csv: 41,22 6,5 6,6 ...

That is, author 22 wrote book 41, and authors 5 and 6 wrote book 6. There are many benefits to this data organization, and we'll revisit those benefits in a week or two when we start talking about relational databases. But for now, these are simply CSV files with a new format that you'll need to deal with.

You may use my data files as-is, or you may prefer to create your own data files with the same format but data more specifically tuned to your unit tests.

Good luck

Start early, ask lots of questions, and have fun!