Basic path testing
The experimental requirements :
Please use the basic path method to design the test case for the function of the previous day .
According to the code obtained from the exchange , Draw a flow chart , Flow chart , Computational cyclomatic complexity , Give an independent path , Design test cases , Perform the test .
Compare the expected results with the actual operation results and give the test conclusion .
flow chart :

Flow chart :

Computational cyclomatic complexity V(G):
Use the formula :V(G) = P +1 have to , The cycle complexity is equal to the number of decision nodes plus one , According to the control flow diagram drawn above , You can know :3、4、5、7、11、14、18、19、21、22、25、29 Yes decision node , share 12 individual , So the cyclomatic complexity is 12 +1 =13.
It can also be further verified , Through the control flow diagram, we can also know , share 13 Regions , Then the cycle complexity is 13.
Give an independent path :
route 1:1->2->3->8->32
route 2:1->2->3->4->9->32
route 3:1->2->3->4->5->10->32
route 4:1->2->3->4->5->6->11->13->32
route 5:1->2->3->4->5->6->11->7->16->17->18->32
route 6:1->2->3->4->5->6->11->12->14->15->32
route 7:1->2->3->4->5->6->11->12->14->19->21->29->31->32
route 8:1->2->3->4->5->6->11->12->14->19->21->29->30->32
route 9:1->2->3->4->5->6->11->12->14->19->21->22->24->32
route 10:1->2->3->4->5->6->11->12->14->19->21->22->23->25->26->28->32
route 11:1->2->3->4->5->6->11->12->14->19->21->22->23->25->27->28->32
route 12:1->2->3->4->5->6->11->12->14->19->20->32
route 13:1->2->3->4->5->6->11->12->18->15->32
Design test cases and compare the results after execution :
Test number | Year | Month | Day | Expected results | The actual result |
1 | 2080 | 3 | 1 | Prompt Please enter the correct year | Prompt Please enter the correct year |
2 | 2020 | 15 | 2 | Prompt Please enter the correct month | Prompt Please enter the correct month |
3 | 2020 | 11 | 35 | Prompt Please enter the correct day | Prompt Please enter the correct day |
4 | 2020 | 4 | 31 | Prompt Please enter the correct day | Prompt Please enter the correct day |
5 | 2000 | 2 | 30 | Prompt Please enter the correct day | Prompt Please enter the correct day |
6 | 2001 | 2 | 29 | Prompt Please enter the correct day | Prompt Please enter the correct day |
7 | 2000 | 3 | 1 | The day before was 2000 year 2 month 29 Number | The day before was 2000 year 2 month 29 Number |
8 | 2001 | 3 | 1 | The day before was 2001 year 2 month 28 Number | The day before was 2001 year 2 month 28 Number |
9 | 2000 | 1 | 1 | The day before was 1999 year 12 month 31 Number | The day before was 1999 year 12 month 31 Number |
10 | 2000 | 5 | 3 | The day before was 2000 year 5 month 2 Number | The day before was 2000 year 5 month 2 Number |
11 | 2000 | 5 | 1 | The day before was 2000 year 4 month 30 Number | The day before was 2000 year 4 month 30 Number |
12 | 2000 | 4 | 1 | The day before was 2000 year 3 month 31 Number | The day before was 2000 year 3 month 31 Number |
13 | 2000 | 4 | 3 | The day before was 2000 year 4 month 2 Number | The day before was 2000 year 4 month 2 Number |
Program code :
import java.util.Scanner; public class test1 { public static void main(String args[]){ Scanner input = new Scanner(System.in); // Enter the month, year and day in sequence System.out.print(" Please enter the date :"); int year = input.nextInt(); int month=input.nextInt(); int day=input.nextInt(); // Judge whether the date is entered as normal if (year<1900||year>2020){ System.out.println(" Please enter the correct year !!!"); return; } if (month<1||month>12){ System.out.println(" Please enter the correct month !!!"); return; } if(day<1||day>31){ System.out.println(" Please enter the correct day !!!"); return; } if (month==4||month==6||month==9||month==11){ if (day==31){ System.out.println(" Please enter the correct day !!!"); return; } } // Judge whether it is a leap year or a non leap year , We'll use that later boolean flag = (year%4==0 && year%100!=0 || year%400==0); // Judge whether the date of February in leap year and normal year is entered correctly if (flag){ if (month==2) { if (day>29){ System.out.println(" Please enter the correct day !!!"); return; } } }else { if (month==2) { if (day>28){ System.out.println(" Please enter the correct day !!!"); return; } } } // Calculate the day before the input date if (day==1){ // If it's the first of every month // If it is 3 January 1st if (month==3){ if(flag){ System.out.println(" The day before was "+year+" year "+"2 month "+"29 Number "); }else { System.out.println(" The day before was "+year+" year "+"2 month "+"28 Number "); } }else{ if (month==1){ System.out.println(" The day before was "+(year-1)+" year "+"12 month "+"31 Number "); }else { month--; if (month==1||month==3||month==5||month==7||month==8||month==10||month==12){ day=31; }else{ day=30; } System.out.println(" The day before was "+year+" year "+month+" month "+day+" Number "); } } }else { System.out.println(" The day before was "+(year)+" year "+month+" month "+(day-1)+" Number "); } } }
Test sample demonstration :
demonstration ( Test number 1):

demonstration ( Test number 2):

demonstration ( Test number 3):

demonstration ( Test number 4):
demonstration ( Test number 5):

demonstration ( Test number 6):

demonstration ( Test number 7):

demonstration ( Test number 8):

demonstration ( Test number 9):

demonstration ( Test number 10):

demonstration ( Test number 11):

demonstration ( Test number 12):

Test conclusion :
Based on the data tested , The program system function of the previous day tends to be stable , The test data within the range required by the experiment have been tested without any problem , This round of test experiment can be ended .








