In this chapter, we will write and test a simple class. This will demonstrate how the "test first" approach introduced in Chapter 1 can be applied in practice. We'll also look at the use of "Design by Contract", and the form that unit tests take.

Suppose we are implementing a collection class` Relation`

representing a mathematical relation. A` Relation`

of size N simply consists of a set of pairs of objects (ai, bi), where i = 1, 2,…, N. The set of objects {ai} is called the domain, and the set of objects {bi} is called the range.

A relation between the letters {A, B, C} and the numbers {1, 2, 3, 4} is ...

Start Free Trial

No credit card required