CSC161 2010F Imperative Problem Solving
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Summary:
Prerequisites: Familiarity with functions, separate compilation, and arrays.
a. Create a directory for this lab.
b. Copy into that directory two files:
/home/rebelsky/share/sorting/bs.h
/home/rebelsky/share/sorting/jqbs.c
c. Read bs.h
to familiarize yourself with the purpose and
form of the binary_search
routine.
Let's start with some very simple tests for the routine.
a. Create a file, bstest1.c
, that contains a main
routine that implements the following test:
{ 1, 5, 9, 21 }
, binary_search
returns 0 when looking for 1.
b. Create a Makefile to build a tester. You might use a rule like
jqtest1: bstest1.o jqbs.o $(CC) -o jqtest1 bstest1.o jqbs.o
c. Build and run your tester. Did you find any errors?
d. Add some more tests.
binary_search
returns 1 when looking for 5.
binary_search
returns 3 when looking for 21.
binary_search
returns -1 when looking for 0.
binary_search
returns -1 when looking for 7.
binary_search
returns -1 when looking for 22.
e. Build and run your tester. Did you find any errors?
a. Write a program, bstest2.c
, that permits more interactive
testing of binary_search
. Your program should
Note: You may find it helpful to look at the code we wrote for the
interactive tester for the average
procedure.
b. Add an entry to the Makefile to build a tester for jqbs.c
.
c. Build and run your tester. Did you find any errors?
The tests in exercise 1 are not very systematic. For example, we never check what happens if the value is not in the array, and is between element 0 and element 1. (Surprisingly, there are many implementations of binary search which work correctly when looking between elements 1 and 2, but not between elements 0 and 1.) One advantage of using computers to do testing is that they can systematically generate a large number of tests. For example, if we generate the array { 0, 2, 4, 6, 8, 10 }, we know that
Write a tester that uses this strategy. You may also add any variants you consider appropriate.
Did you find any errors?
If you find yourself with extra time, implement binary search yourself.
Wednesday, 6 October 2010 [Samuel A. Rebelsk]
Friday, 8 October 2010 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Schedule]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
-
[Assignment]
[Lab]
Groupings:
[EBoards]
[Assignments]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Fri Oct 8 11:43:30 2010.
The source to the document was last modified on Fri Oct 8 11:43:28 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Labs/testing-lab.html
.
A PDF version of this document may be found at
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Labs/testing-lab.pdf