Question: Suppose that a developer needs to test a function (named, compdate ) that compares dates with the following specification: int compdate (int year1 , int
Suppose that a developer needs to test a function (named, compdate) that compares dates with the following specification:
int compdate(int year1, int month1, int day1, int year2, int month2, int day2);
/* compdate returns 0 if date1 = date2, -1 if date1 before date2, 1 if date1 after date2, -2 if any element of any date is invalid; valid years are all integers (<0 >
The developer decides to use a random testing scheme to test the compdate function, and also decides to run 200 tests where each test is performed by the following function:
int randomtest_compdate() {
int i;
for (i=0; i<200; i++){ int y1 = random_int(); /* returns a random 32 bit value */ int y2 = random_int(); int m1 = (random_int() % 11) + 1; int m2 = (random_int() % 11) + 1; int d1 = (random_int() % 30) + 1; int d2 = (random_int() % 30) + 1; int c = compdate(y1,m1,d1,y2,m2,d2); oracle(y1,m1,d1,y2,m2,d2,c);
}
}
Assuming that oracle function does a good job of checking compdates correctness:
Discuss the random testing approach and propose how to improve it (at least three improvements).
For each improvement, explain the weakness of the original scheme.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
