Error and Boundary Conditions for photo_sorter
The error conditions that I tested for are:
- invalid command: an invalid command is one other than the five you
were asked to implement for this lab.
- wrong number of arguments to a command: for each command you should
check to make sure that the correct number of arguments was supplied.
- for delete, after, and before only: check for a non-existent target
node and print an error message if the target node is not found.
The boundary and unusual conditions that I tested were:
- a set of insertions, followed by a set of deletions that created an
empty list. Then I did some more insertions to make sure that the list
was still working properly. The boundary condition was the empty list.
- a before command that inserted before the first node in the list. The
boundary condition is inserting at the front of the list.
- an after command that inserted after the last node in the list. The
boundary condition is inserting at the end of the list.
- a large number of insertions that makes the list grow large. The goal
was to stress test the list by creating a very large list.
- an empty set of commands. The program should do nothing in this case.
Make sure it does nothing.
- a blank line in the commands. The line should be skipped and the program
should move onto the command on the next line.
Error and Boundary Conditions for linenum
The error conditions that I tested for are:
- Wrong number of command line arguments
- Inability of new_inputstruct to open the file.
The boundary and unusual conditions that I tested for are:
- an empty file
- a file with a single line
- a file with words that appear multiple times on the same line (i.e.,
would lead to duplicate line numbers unless you prevent line numbers
from being duplicated).
- a file with words that appear on multiple lines
Design Steps for linenum
is the most complicated program you have written thus far in the course and
if you try to write it all at once you are almost guaranteed to fail to get
it working properly. Further, the TAs will not be able to help you debug your
code because it will be too complicated. It is essential that you
code this program in baby steps. Doing so will also make the program
conceptually easier to handle.
Here are the incremental steps I used for creating the linenum program:
- I created a dllist for the words and an inputstruct for the file.
- I created a struct for a word. The struct held only the name of the
word initially. Later I added a line number list to this struct.
- I wrote a loop to read each line in the file and an inner loop to
traverse each word in a line. For each word I created a word struct
and inserted the word struct at the end of the list. I did not bother
to check for duplicates or try to alphabetize the words. When I was
done processing the file I traversed the list and printed out the words.
This allowed me to make sure that I could insert the word struct into
the word list and then retrieve word structs in order to print the
- I refined the previous step so that I only added a word to the word
list if it was not previously there. I did alphabetize the word list
during this step. Specifically for each word on a line, I wrote a
search loop to
see if the word was not yet in the word list (the search loop will be
nested inside the loop that traverses the words on a line). If I found the
word I simply broke out of the search loop and continued with the next word.
If I found a word in the list that was greater than the one I was
looking for, I knew the word was not in the list. I allocated a word
struct and used
dll_insert_before to insert my word before this greater word.
I then broke out of the search loop.
- After processing each word I printed the list of words thus far to make sure it
it was in alphabetical order and contained no duplicates. My initial
list did contain duplicates. This incremental step allowed me to catch
this error early and the correction was simple.
I also made sure that boundary conditions were tested, which
included inserting before the first word in the list and inserting after
the last word in the list. Notice that I did not try to do anything
with line numbers yet. I was only concerned with getting the words into
- I now added code to handle the line number lists and I re-used my
linenum code from lab 6 as much as possible. I first added a line
number list field to my word struct. Then I divided my task into two
These two cases were already separated in the code I had written in
the previous step, so dividing the task in two was no problem.
- Case 1--The word is not yet in the word list: In this case
I allocated a new line number list (use either new_sllist or new_dllist,
depending on whether you use singly or doubly-linked lists for the
line number list), assigned the new list to the word's new word struct,
and appended the line number to the line number list. I tested this
case before moving on to case 2. Make it easy on yourself by testing
it with a single line program with three or four words, then try it
with several lines of words, but make sure no word is duplicated in the
- Case 2--The word is already in the word list: In this case
I used my code
from lab 6 to see if the line number was already in the word's line
number. If it was not, then I added the line number to the list.
In this step I also had to augment the printing code so that it
printed out line numbers for each word.
I first tested my code with no word being duplicated on the same line,
and once that worked, then I put duplicates on the same line. I kept
my testing simple at first, by using a single line file, and then
worked up to multiple line files.
- I added error checking code.