Testing and the Final Solution
Objectives
We would like to :- Discuss testing our classes
- Discuss Utilities that will help with the problem solution.
- Discuss the final solution to the problem.
Notes
- When we test we need to make sure that we call ALL of the methods.
- For all the cases we can think of
- Initialize a word
- Default,
- with a clean parameter
- With a raw parameter
- Test all of the increment functions.
- Test all of the compare functions
- It is frequently useful to write functions to help with this.
- Take a look at WordCountTest.cpp.
- Note the PrintAndTest function
- Note the CompareWords function.
- I am not the happiest with this, as it requires me to read the output.
- A better test would just say "pass" if everything is good and print an error for all bad results.
- But this is currently outside the scope of our class.
- When working on the test driver for the array, I decided to create a utility library
- Print the array
- Insert a word in the array,
- This is structured so it
- Checks to see if the word is already there, and increments it if it is.
- If not checks to see if there is space, and inserts the word if there is.
- If not prints an error message.
- This is structured so it
- I also added a Find function (for the above routine)
- A Sort by word function
- A sort by count function.
- Do these functions belong in the Class definition?
- I don't think so, but you might.
- Selection Sort
- Takes an array
- Returns the array ordered
-
void SelectionSort(DataT array[], int size) { size_t small; for(size_t current = 0; current < size; ++current) { size_t small = current; for(size_t j = current + 1; j < size; ++j) { if (array[small] > array[j]) { small = j; } } if (small != current) { DataT tmp {array[small]}; array[small] = array[current]; array[current] = tmp; } } }