Tutorial-12: To calculate the value of previous date and generate its Decision Table based Test Cases
Inputs for the Tutorial: The present Date is an input as two integers a & b.
Objective of this Tutorial: There are two objectives of the tutorial like:
Objective 1: To write a Program in C++ for the determining the value of previous dates based upon various combinations of present date as input.
Objective 2:
Decision Table Based testing for situations in which a number of combinations of actions shall be taken for different conditions. Four parts of decision table being covered shall be: Condition Stub, Action Stub, Condition Entries and Action Entries.
Solution Part 1: Program in C++
#include
#include
int main()
{
int day, month, year, flag=0;
printf(” enter the day value;”);
scanf(“%d”,&day) ;
printf(“enter the month value;”);
scanf(“%d”,&month);
printf(“enter the year value;”);
scanf(“%d”,&year) ;
if(year> = 1900 && year< = 2025)
{
if(month==l||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day> = 1&&day<=31)
{
flag = 1;
}
else
{
flag = 0;
}
}
elseif (month==2)
{
int rval=0;
if(year%4==0)
{
rval=l;
if((year%100)==0 && (year%400)! = 0
{rval = 0;
}
}
if(rva1==&&(day>=1 &&day <=29))
{ flag = 1;
}
elseif (day>=1 &&day <=28)
{ flag = 1;
else
}
flag = 0;
}
}
if (flag)
{
if(day==1)
{
if(month==1)
{
year–;
day = 31;
month = 12;
}
else if(month==3)
{
int rval = 0;
if(year%4==0)
{
rval = 1;
if ((year%100) == 0 && (year%400): = 0)
{ravl = 0;
}
}
if (ravl==1)
{
day = 29;
month–;
}
else
{
day = 28;
month–;
}
}
else if (month==2|| month==4||month==6||month==9||month==)
{day = 31;
month–;
}
else
{
day = 30;
month–;
}
}
else
{
day–;
}
printf (“the next data is:%d-%d-%d”, day, month, year) ;
}
else
{
printf (“the entered data is invalid: %d-%d-%d, day, month, year)
{
getche();
return 1;
}
Solution Part 2: Decision Table Based Test Cases
Test Case ID | Month | Day | Year | Expected Output |
1 | June | 1 | 1964 | 31 May 1964 |
2 | June | 21 | 1984 | Impossible |
3 | May | 1 | 1945 | 30 April 1945 |
4 | March | 31 | 2007 | 30 March 2007 |
5 | August | 29 | 2007 | 28 August 2007 |
6 | February | 29 | 1962 | Impossible |
Screenshot with a sample output is as under:
Many More Articles & Tutorials on Black Box Testing
An expert on R&D, Online Training and Publishing. He is M.Tech. (Honours) and is a part of the STG team since inception.
At last, someone comes up with the \”right\” ansewr!