0% found this document useful (0 votes)
3 views

Prog 2

The document outlines the implementation of a NextDate function in C, including a leap year check and input validation for day, month, and year. It details the equivalence class value testing approach, providing various test cases categorized into weak normal, weak robust, strong normal, and strong robust. Each test case includes descriptions, inputs, expected outputs, and comments on the validity of the inputs.

Uploaded by

skjskjskj333
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Prog 2

The document outlines the implementation of a NextDate function in C, including a leap year check and input validation for day, month, and year. It details the equivalence class value testing approach, providing various test cases categorized into weak normal, weak robust, strong normal, and strong robust. Each test case includes descriptions, inputs, expected outputs, and comments on the validity of the inputs.

Uploaded by

skjskjskj333
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

2.

Design, develop, code and run the program in any suitable language to implement the
NextDate function. Analyze it from the perspective of equivalence class value testing, derive
different test cases, execute these test cases and discuss the test results.

#include <stdio.h>

#define TRUE 1
#define FALSE 0

// Function to check if a year is a leap year


int isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
return TRUE;
} else {
return FALSE;
}
}

int main() {
int day, month, year;
int tomorrowDay, tomorrowMonth, tomorrowYear;
int c1, c2, c3;

do {
printf("Enter today's date in the form DD MM YYYY: ");
scanf("%d %d %d", &day, &month, &year);

c1 = (1 <= day) && (day <= 31);


c2 = (1 <= month) && (month <= 12);
c3 = (1812 <= year) && (year <= 2012);

if (!c1) {
printf("Value of day not in the range 1..31\n");
}
if (!c2) {
printf("Value of month not in the range 1..12\n");
}
if (!c3) {
printf("Value of year not in the range 1812..2012\n");
}
} while (!(c1 && c2 && c3));

tomorrowYear = year;
tomorrowMonth = month;
tomorrowDay = day;
switch (month) {
case 1: case 3: case 5: case 7: case 8: case 10: // 31 day months (except December)
if (day < 31) {
tomorrowDay = day + 1;
} else {
tomorrowDay = 1;
tomorrowMonth = month + 1;
}
break;
case 4: case 6: case 9: case 11: // 30 day months
if (day < 30) {
tomorrowDay = day + 1;
} else if (day == 30) {
tomorrowDay = 1;
tomorrowMonth = month + 1;
} else {
printf("Invalid Input Date\n");
return 1;
}
break;
case 12: // December
if (day < 31) {
tomorrowDay = day + 1;
} else {
tomorrowDay = 1;
tomorrowMonth = 1;
if (year == 2012) {
printf("Invalid Input Date\n");
return 1;
} else {
tomorrowYear = year + 1;
}
}
break;
case 2: // February
if (day < 28) {
tomorrowDay = day + 1;
} else if (day == 28) {
if (isLeapYear(year)) {
tomorrowDay = 29;
} else {
tomorrowDay = 1;
tomorrowMonth = 3;
}
} else if (day == 29) {
if (isLeapYear(year)) {
tomorrowDay = 1;
tomorrowMonth = 3;
} else {
printf("Invalid Input Date\n");
return 1;
}
} else {
printf("Invalid Input Date\n");
return 1;
}
break;
default:
printf("Invalid Input Date\n");
return 1;
}

printf("Tomorrow's date is %02d/%02d/%04d\n", tomorrowDay, tomorrowMonth,


tomorrowYear);
getch();
return 0;
}

Output:
Equivalence Classes are as follows:
D1= { Day/DD : 1<=DD<=31 }
M1= { Month/MM : 1<=MM<=12 }
Y1= { Year /YY: 1812<=YY<=2015 }

Weak Normal /Strong Normal


Test Inputs
Description Output Comments
cases DD MM YY
WN/SN1 Enter valid values for day, 12 2 1990 13/2/1990 Valid
month and year from
equivalence classes.

Weak Robust
Test Inputs
Description Output Comments
cases DD MM YY
WR1 Enter valid values for month -1 6 1992 Value of day Valid
and year from equivalence not in the
classes and invalid value for range 1..31
day.
WR2 Enter valid values for day and 15 -1 1992 Value of Valid
year from equivalence classes month not in
and invalid value for month. the range
1..12
WR3 Enter valid values for day and 15 6 1811 Value of Valid
month from equivalence year not in
classes and invalid value for the range
year. 1812..2012
WR4 Enter valid values for month 32 6 1992 Value of day Valid
and year from equivalence not in the
classes and invalid value for range 1..31
day.
WR5 Enter valid values for day and 15 13 1992 Value of Valid
year from equivalence classes month not in
and invalid value for month. the range
1..12
WR6 Enter valid values for day and 15 6 2016 Value of Valid
month from equivalence year not in
classes and invalid value for the range
year. 1812..2012

Strong Robust
Test Inputs Comme
Description Output
cases DD MM YY nts
SR1 Enter valid values for month and year -1 6 1992 Value of day not in Valid
from equivalence classes and invalid the range 1..31
value for day.
SR2 Enter valid values for day and year 15 -1 1992 Value of month Valid
from equivalence classes and invalid not in the range
value for month. 1..12
SR3 Enter valid values for day and month 15 6 1811 Value of year not Valid
from equivalence classes and invalid in the range
value for year. 1812..2012
SR4 Enter valid value for year from -1 -1 1992 Value of day not in Valid
equivalence classes and invalid values the range 1..31
for day and month. Value of month
not in the range
1..12
SR5 Enter valid value month for from -1 6 1811 Value of day not in Valid
equivalence classes and invalid values the range 1..31
for day and year. Value of year not
in the range
1812..2012
SR6 Enter valid value for day from 15 -1 1811 Value of month Valid
equivalence classes and invalid values not in the range
for month and year. 1..12
Value of year not
in the range
1812..2012
SR7 Enter valid values for month and year 32 6 1992 Value of day not in Valid
from equivalence classes and invalid the range 1..31
value for day.
SR8 Enter valid values for day and year 15 13 1992 Value of month Valid
from equivalence classes and invalid not in the range
value for month. 1..12
SR9 Enter valid values for day and month 15 6 2016 Value of year not Valid
from equivalence classes and invalid in the range
value for year. 1812..2012
SR10 Enter valid value for year from 32 13 1992 Value of day not in Valid
equivalence classes and invalid values the range 1..31
for day and month. Value of month
not in the range
1..12
SR11 Enter valid value month for from 32 6 2016 Value of day not in Valid
equivalence classes and invalid values the range 1..31
for day and year. Value of year not
in the range
1812..2012
SR12 Enter valid value for day from 15 13 2016 Value of month Valid
equivalence classes and invalid values not in the range
for month and year. 1..12
Value of year not
in the range
1812..2012
SR13 Enter invalid values for day, month -1 -1 1811 Value of day not in Valid
and year. the range 1..31
Value of month
not in the range
1..12
Value of year not
in the range
1812..2012
SR14 Enter invalid values for day, month 32 13 2016 Value of day not in Valid
and year. the range 1..31
Value of month
not in the range
1..12
Value of year not
in the range
1812..2012

You might also like