Algorithms and OOD (CSC 207 2014S) : Labs

Laboratory: Implementing Dictionaries with Association Lists

Summary: We extend our understanding of Dictionaries by considering one simple approach to implementing dictionaries: Association Lists. Association lists are simply lists of key/value pairs.

Prerequisite Knowledge: Linked lists. Dictionaries.


Fork and clone the repository at


Exercise 1: Thinking About Testing

We should, of course, begin our exploration of code by designing unit tests for that code. Suppose we are focusing primarly on the primary operations of put, get, and remove.

Read through the tests that are there. Then note what aspects of the three methods we are failing to test. (You don't need to add these tests; just think about how the tests are incomplete.)

Exercise 2: Reading Code

It's sometimes nice to read other people's code before we are biased by test results. So let's look at the underlying code.

a. Prepare to describe to someone else how the code is designed. What are the big-picture design decisions? How are different methods implemented? What are tricks that the designers have attempted?

b. Identify likely trouble spots in the code. What potential issues do you see?

Exercise 3: Checking and Correcting Errors

a. Given your reading of the code and the tests, which tests do you expect to succeed and which tests do you expect to fail?

b. Check your answer by running the tests.

c. Correct any bugs in the code the tests have identified.

Exercise 4: More Black-Box Testing

In an earlier exercise, you identified missing black-box tests. Write a few of those tests.

If the tests identify errors, correct the code.

Exercise 5: White-Box Testing

Traditionally, when designing unit tests we focus primarily on the client's perspective of the code. But when we know the underlying implementation, we also have the opportunity to think about particular areas in which the implementation may be more fragile. Hence, we can design tests that focus on the implementation and not just interface. This approach is often called “white-box” or “clear-box” testing.

When you looked at the underlying implementation, you identified some potential trouble spots. Write a few white-box tests that explore those potential issues.

For Those With Extra Time

Implement iterators.

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.