CMPS-3350 Coding Exam
Useful materials and links: program framework unit-test data
Do your work in your Odin /3350/b/ folder.
Log on to Odin, then do this...$ /home/fac/gordon/p/3350/lab-setup.sh $ umask 027
Start with the given C++ program$ cd 3350/b $ cp /home/fac/gordon/public_html/3350/mid/for-students.txt mylab11.cpp
Sample output of the starting program...$ ./lab11 Calculate days between dates. Days between Nov 5, 2024 and Nov 5, 2024 is: 0 Days between Nov 5, 2024 and Nov 6, 2024 is: 1 Days between Nov 1, 2024 and Nov 30, 2024 is: 29 Days between Nov 1, 2024 and Dec 1, 2024 is: 40000000 ... ...
Files to be collected: ------------------------------- 3350/b/mylab11.cpp 3350/b/Makefile
What to do...
Write a unit-test procedure to test a member function of the Date class.
Function name is: Date::operator++
Add the following components to this assignment. 1. A Unit Test of the Date::operator++ member function. ==================================================== The function is already started, but is not finished yet. This function must increment a date by 1-day each time it is called. When day is incremented, the value of day will change. If day goes beyond the number of days in the month, month must change. If month goes beyond December, the year must change. 2. Get the test data from unit-test data. ====================================== Use the data to perform your unit-test. Show nice output similar to the example below. 3. Isolate your unit-test. ======================= Isolate the code with preprocessor directives such as #ifdef, #endif. Use a #define name of UNIT_TEST. Isolate all components of your unit-test. Store the unit-test data in your mylab11.cpp file. 4. Provide a Makefile to produce two executable files. =================================================== One is the original program. The second executable is the unit-test executable. The original program executable must work normally when run. When you finish your Unit-test, your original program should work.Output when you first run your program...
$ ./lab11 Calculate days between dates. Days between Nov 5, 2024 and Nov 5, 2024 is: 0 Days between Nov 5, 2024 and Nov 6, 2024 is: 1 Days between Nov 1, 2024 and Nov 30, 2024 is: 29 Days between Nov 1, 2024 and Dec 1, 2024 is: 40000000 Days between Jan 1, 2024 and Jan 1, 2025 is: 40000000 Days between Jan 1, 2025 and Jan 1, 2026 is: 40000000
The result 4,000,000 days means there is an infinite loop. A change in the month is not being handled. Fix it.
Sample output of Unit Tests...
When you start...$ ./utest Unit test of Date class. Specifically testing the pre-increment overloaded operator. A date is incremented by 1-day in that member function. actual expected date1 date2 days days diff ---------- ---------- -------- -------- -------- 11-05-2024 11-06-2024 1 1 0 ok 11-05-2024 11-30-2024 25 25 0 ok 11-05-2024 12-01-2024 40000000 26 39999974 <--- bad result 11-05-2024 01-01-2025 40000000 57 39999943 <--- bad result 01-01-2024 11-05-2024 40000000 309 39999691 <--- bad result 11-05-2024 11-05-2025 40000000 366 39999634 <--- bad result 01-01-2024 01-01-2025 40000000 366 39999634 <--- bad result 01-01-2000 11-05-2024 40000000 9075 39990925 <--- bad result 03-08-3637 04-22-7058 40000000 1249539 38750461 <--- bad result
After fixing the change in month...$ ./utest Unit test of Date class. Specifically testing the pre-increment overloaded operator. A date is incremented by 1-day in that member function. actual expected date1 date2 days days diff ---------- ---------- -------- -------- -------- 11-05-2024 11-06-2024 1 1 0 ok 11-05-2024 11-30-2024 25 25 0 ok 11-05-2024 12-01-2024 26 26 0 ok 11-05-2024 01-01-2025 40000000 57 39999943 <--- bad result 01-01-2024 11-05-2024 308 309 1 <--- bad result 11-05-2024 11-05-2025 40000000 366 39999634 <--- bad result 01-01-2024 01-01-2025 40000000 366 39999634 <--- bad result 01-01-2000 11-05-2024 40000000 9075 39990925 <--- bad result 03-08-3637 04-22-7058 40000000 1249539 38750461 <--- bad result
After fixing the change in year...$ ./utest Unit test of Date class. Specifically testing the pre-increment overloaded operator. A date is incremented by 1-day in that member function. actual expected date1 date2 days days diff ---------- ---------- -------- -------- -------- 11-05-2024 11-06-2024 1 1 0 ok 11-05-2024 11-30-2024 25 25 0 ok 11-05-2024 12-01-2024 26 26 0 ok 11-05-2024 01-01-2025 57 57 0 ok 01-01-2024 11-05-2024 308 309 1 <--- bad result 11-05-2024 11-05-2025 365 366 1 <--- bad result 01-01-2024 01-01-2025 365 366 1 <--- bad result 01-01-2000 11-05-2024 9068 9075 7 <--- bad result 03-08-3637 04-22-7058 1248710 1249539 829 <--- bad result
After fixing leap-year, but not completely...$ ./utest Unit test of Date class. Specifically testing the pre-increment overloaded operator. A date is incremented by 1-day in that member function. actual expected date1 date2 days days diff ---------- ---------- -------- -------- -------- 11-05-2024 11-06-2024 1 1 0 ok 11-05-2024 11-30-2024 25 25 0 ok 11-05-2024 12-01-2024 26 26 0 ok 11-05-2024 01-01-2025 57 57 0 ok 01-01-2024 11-05-2024 309 309 0 ok 11-05-2024 11-05-2025 365 365 0 ok 01-01-2024 01-01-2025 366 366 0 ok 01-01-2000 11-05-2024 9075 9075 0 ok 03-08-3637 04-22-7058 1249565 1249539 26 <--- bad result 11-17-0485 03-24-6240 2101776 2101732 44 <--- bad result
How to know if a year is a leap-year ------------------------------------ To be a leap year, the year number must be divisible by four. Except for end-of-century years, which must be divisible by 400. An end-of-century year is divisible by 100. Not a leap year, unless it's also divible by 400. The year 2000 was a leap year. The year 1900 was not. How do you add a day to a leap-year? Good question. Answer: in the month of February.
Elements not allowed in this assignment --------------------------------------- 1. #include <chrono> 2. #include <ctime> 3. #include <date.h>
Files to be collected: ------------------------------- 3350/b/mylab11.cpp 3350/b/Makefile