Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

David needs to test a function that compares dates (in C) with the following spe

ID: 666875 • Letter: D

Question

David needs to test a function that compares dates (in C) with the following specification:

/* 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 = BC); valid month is 1-12; valid day is
1-{28,29,30,31} depending on the year and month */
int compdate(int year1, int month1, int day1, int year2, int month2, int day2);

He proposes a random testing scheme, running 2,000,000 tests where each test is
performed by the following function:

int oneTest() {
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 c1 = compdate(y1,m1,d1,y2,m2,d2);

int c2 = compdateOracle(y1,m1,d1,y2,m2,d2);

Assert(c1 == c2, "Issue with compdate function");

}

Assuming that compdateOracle is a perfect function without any bug to compare dates, Find out 3 issues with this random testing scheme. For each of the issue found, propose an improvement. Mention issue in one line and improvement proposal in less then 3 lines. Find out logical issue, don't look for typos and coding errors.

David needs to test a function that compares dates (in C) with the following specification:

/* 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 = BC); valid month is 1-12; valid day is
1-{28,29,30,31} depending on the year and month */
int compdate(int year1, int month1, int day1, int year2, int month2, int day2);

He proposes a random testing scheme, running 2,000,000 tests where each test is
performed by the following function:

int oneTest() {
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 c1 = compdate(y1,m1,d1,y2,m2,d2);

int c2 = compdateOracle(y1,m1,d1,y2,m2,d2);

Assert(c1 == c2, "Issue with compdate function");

}

Assuming that compdateOracle is a perfect function without any bug to compare dates, Find out 3 issues with this random testing scheme. For each of the issue found, propose an improvement. Mention issue in one line and improvement proposal in less then 3 lines. Find out logical issue, don't look for typos and coding errors.

Explanation / Answer

Here some of issues I found...

1) int y1 = random_int();

this random int gives number which it may lies in boundary 0 to infinty ...

So in this statement issue occurs..since maximum year digits accepted is 4

solution

so change it to ...int y1 = random_int() /1000;

2) int d1 = (random_int() % 30) + 1;

In this statement we will get number of days where boundary lies between 1 to 31 which is good. But issue occurs when month february selected/...then it may given number of days as 30 or 31...so this woulb raise error.

Solution.. handle with if conditions ...for 6 months we have only 30 days and 5 months 31 days and one month 28 days

3) int c1 = compdate(y1,m1,d1,y2,m2,d2);

As already we discussed above problems....so when we comparing with those wrong values then it will wrong values..and may be throw exception..so use try catch exception class...