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

Suppose that David needs to test a function (named, compdate ) that compares dat

ID: 3735490 • Letter: S

Question

Suppose that David 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 = BC); valid month is 1-12; valid day is
1-{28,29,30,31} depending on the year and month */


David decides to use a random testing scheme to test the compdate function, he 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 compdate’s correctness:

Discuss the random testing approach and propose how to improve it.

For each improvement, explain the weakness of the original scheme.

Explanation / Answer

I think this is a best approach to test compdate function.  

but at the end we should check oracle function result and compdate function result. If both are same ther our compdate function is working properly.  

for example:-

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);
int b = oracle(y1,m1,d1,y2,m2,d2,c);

if(b ==c ) {

//compdate function s working properly

} else {

// Something is wrong with compdate function. and show both dates in output. So that tester can understand //issue.

break;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote