Due: 11: a.m., Wednesday, 6 April 2011
Summary: Document, test, and implement a set intersection procedure.
Purposes: To experience test-first program development; to practice writing documentation; to gain further experience with recursion, precondition checking, and locally-bound helper procedures.
Expected Time: One to two hours.
Collaboration: We encourage you to work in groups of size three. You may, however, work alone or work in a group of size two or size four. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.
Submitting:
Email your answer to <grader-151-01@cs.grinnell.edu>. The title of your email
should have the form CSC151-01 Assignment 6: Set Intersection and
should contain your answers to all parts of the assignment. Scheme code
should be in the body of the message.
Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.
After graduation, you and your colleagues move to Schemeville to found a new company, Sets-R-Us. Your business plan is to develop a library of procedures for set manipulation and sell it to Scheme programmers all over the world (or maybe just computer science professors at Grinnell College). You know that you need thorough documentation and reliable code for your product to sell.
You decide to begin with the set intersection operation. You need to
write a procedure,
(, that takes two lists as parameters.
It produces a list containing precisely those values that occur in both
intersect left
right)left and right.
Although left and right
might include duplicate values, the value that is produced should not have
any duplicates.
Note that the above description of intersect
does not specify the order in which the values will occur in the
result; your tests should not assume a particular order. Fortunately,
the unit test framework lets us test permutations (with
test-permutation!).
For example, we might write a test such as the following.
(test-permutation! (intersection (list 1 2) (list 3)) (list 1 2 3))
This indicates
that we want the values 1, 2, and 3 to appear in the resulting list, but
we don't care what order those values appear in. The list (1 2
3) would be a valid result, and so would (3 2 1), and
even (2 3 1).
(a)
The above description of the intersect procedure is clearly
casual. Write formal documentation
for intersect, using the six P's.
(b) Write a test suite, using test-permutation! and
the rest of the MediaScheme unit testing
tools,
that will help you and your colleagues test for errors in an
implementation of intersect.
You should be confident that anything that passes your test suite is
correct. (You might also want to be able to use this test suite to
convince potential customers that your implementation is correct!)
(c) Finally, write your own implementation of the
intersect procedure. If the user calls your
procedure in ways that do not satisify the preconditions, your procedure
should give a helpful error message. If you use the husk-and-kernel style
for checking preconditions
(and I encourage you to do so), then hide the kernel using letrec
or named let.
We will evaluate the carefulness of your documentation, the completeness of your tests, and the correctness and elegance of your implementation.
Copyright © 2007-2011 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a
Creative Commons Attribution-NonCommercial 2.5 License
.