|
|
|
|
|
|
|
would look at the months. If the months were the same, we would have to look at the days. As so often happens, we can use this algorithm directly in our function. |
|
|
|
 |
|
|
|
|
ComparedTo (In: otherDate)
Out: Function value |
|
|
|
|
|
|
|
|
IF yr < otherDate.yr
Return BEFORE
IF yr > otherDate.yr
Return AFTER
//Years are equal. Compare months
IF mo < otherDate.mo
Return BEFORE
IF mo > otherDate.mo
Return AFTER
//Years and months are equal. Compare days
IF day < otherDate.day
Return BEFORE
IF day > otherDate.day
Return AFTER
//Years, months, and days are equal
Return SAME |
|
|
|
|
|
|
|
|
|
Testing: In testing this function, each path must be taken at least once. Case Study Follow-Up Exercise 2 asks you to design test data for this function and to write a driver that does the testing. |
|
|
|
|
|
|
|
|
The Increment function: The algorithm to increment the date is similar to our earlier algorithm for incrementing a TimeType value by one second. If the current date plus 1 is still within the same month, we are done. If the current date plus 1 is within the next month, then we must increment the month and reset the day to 1. Finally, we must not forget to increment the year when the month changes from December to January. |
|
|
|
|
|
|
|
|
To determine whether the current date plus 1 is within the current month, we add 1 to the current day and compare this value with the maximum number of days in the current month. In this comparison, we must remember to check for leap year if the month is February. |
|
|
|
|
|