In this, we will test our program to check whether it can give the previous date as an output or not. We are supposing interval [2000,2050] for year, [1,31] days for date, [1,12] for month. If we observe closely, we require to figure out whether the year input is a leap year or not between the selected year interval.
We will be applying Boundary Value Analysis to generate test cases. The expected output can be [Invalid date, previous Date].
Program:
#include<conio.h> #include<stdio.h> void main() { int month,date,year, valid=-1,leap_year=-1; printf("please enter a date = "); scanf("%d",&date); printf("please enter a month = "); scanf("%d",&month); printf("please enter a year = "); scanf("%d",&year); if((date>0 && date<=31)&&(month>=1 && month<=12)&&(year>=2000 && year<=2050)) { // finding given input is a leap year or not if((year%4)==0) { leap_year=1; if((year%100)==0) { if((year%400)==0) { leap_year=1; } else { leap_year=-1; } } } if(month==2 && leap_year==1 && date >29) valid=-1; else if(month==2 && leap_year==-1 && date >28) valid=-1; else valid=1; } if((month==6 || month==4||month==9||month==11) && date>30) valid=-1; // validating & finding output if(valid==1) { printf("Entered date = %d-%d-%d",date,month,year); if(date==1) { if(month==1) { date=31; month=12; year--; } else if(leap_year=1 && month==3) { date=29; month--; } else if(leap_year==-1 && month==3) { date=28; month--; } else if(month==2||month==4||month==6||month==8||month==9||month==11){ date=31; month--; }else{ date=30; month--; } } else{ date--; } printf("\nPrevious date = %d-%d-%d \n",date,month,year); } else printf("\n Not a valid date"); getch(); }
So, there will be 4N+ 1 test cases that is 4*3 +1 =13 in this case as we are using boundary value analysis.
Test ID | Date | Month | Year | Expected Output | Program Output | Test Outcome |
---|---|---|---|---|---|---|
1 | 1 | 6 | 2025 | 31-5-2025 | 31-5-2025 | Pass |
2 | 2 | 6 | 2025 | 1-6-2015 | 1-6-2015 | Pass |
3 | 30 | 6 | 2025 | 29-6-2015 | 29-6-2015 | Pass |
4 | 31 | 6 | 2025 | Invalid Date | Invalid Date | Pass |
5 | 15 | 1 | 2025 | 14-1-2025 | 14-1-2025 | Pass |
6 | 15 | 2 | 2025 | 14-2-2025 | 14-2-2025 | Pass |
7 | 15 | 11 | 2025 | 14-11-2025 | 14-11-2025 | Pass |
8 | 15 | 12 | 2025 | 14-12-2025 | 14-12-2025 | Pass |
9 | 15 | 6 | 2000 | 14-6-2000 | 14-6-2000 | Pass |
10 | 15 | 6 | 2001 | 14-2-2001 | 14-2-2001 | Pass |
11 | 15 | 6 | 2049 | 14-6-2049 | 14-6-2049 | Pass |
12 | 15 | 6 | 2050 | 14-6-2050 | 14-6-2050 | Pass |
13 | 15 | 6 | 2025 | 14-6-2025 | 14-6-2025 | Pass |
Testing the program:
Invalid Date:
Previous Date: