Академический Документы
Профессиональный Документы
Культура Документы
9/19/2001 © Ye Wu 1 9/19/2001 © Ye Wu 2
1
How to Derive CFG – if-else How to Derive CFG – while
S1 S1
S1
If (e) S1
if-else while
S2 e -e while (e) e
Else S2 -e
S3 S2 S3 end while S2
endif S3
S4 S4 S3
9/19/2001 © Ye Wu 7 9/19/2001 © Ye Wu 8
S1
for
S1 i≤B S1
for i = A to B do repeat S2
S2
S2
S2 -e
i>B
end for until (e) repeat
i= i+1
S3 S3 e
S3
S3
9/19/2001 © Ye Wu 9 9/19/2001 © Ye Wu 10
2
System.out.print("Please input an integer:");
InputStreamReader isr = Sa
new InputStreamReader (System.in); S1
S1 BufferedReader br = S1;
new BufferedReader (isr); if (t > 0) {
t = Integer.parseInt(br.readLine()); for( i = 2; p; i++) {
flag = false; if ( t % i == 0) if-else
if (t > 0) { S2 t>0 t >=0
for( i = 2; i <= ( int)Math.sqrt((double)t); i++) { }
if ( t % i == 0) { if (!flag) Sa S4
System.out. println("It's COMPOSITE number!"); S3
S2 flag = true; else
break; } S4 Send
} S3 S4
if (!flag) System.out.println("It's PRIME number");
}
else System.out.println("Please input a positive NUM!");
9/19/2001 © Ye Wu 13 9/19/2001 © Ye Wu 14
t>0 S1 t>0 S1
S1; S1;
if (t > 0) { Sb if (t > 0) {
for for( i = 2; p; i++) { for
for( i = 2; p; i++) { p p
if ( t % i == 0) if ( t % i == 0)
Sb t >=0 if t >=0
S2 !p S2 !p
} }
S2 X
if (!flag) i++; i++;
S3 if (!flag)
else if S3 if
!flag !flag
S4 else
flag flag
S3 S4 S4 S3 S4
Send Send
9/19/2001 © Ye Wu 15 9/19/2001 © Ye Wu 16
9/19/2001 © Ye Wu 17 9/19/2001 © Ye Wu 18
3
Basic Path Coverage Techniques (2) Example
Test case 1: a=1 b=1 c= 1 BC
• Conditional coverage Test case 2: a=1 b=1 c = -1
– Every condition in every decision has evaluated to both
Test case 3: a=1 b =-1 c= 1
True and False for at least once
Test case 4: a=1 b =-1 c = -1
CC MC/DC
Test case 5: a =-1 b=1 c= 1
• Multiple condition/Decision coverage(MC/DC)
Test case 6: a =-1 b=1 c = -1
– Every decision and every condition within the decision
have taken every outcome at least once
Test case 7: a =-1 b =-1 c= 1
Test case 8: a =-1 b =-1 c = -1
9/19/2001 © Ye Wu 19 9/19/2001 © Ye Wu 20
9/19/2001 © Ye Wu 21 9/19/2001 © Ye Wu 22
9/19/2001 © Ye Wu 23 9/19/2001 © Ye Wu 24
4
Special Considerations Effectiveness of Path Testing
• Handling loops in path testing • Can caught about 60% bugs in unit testing
– Run the loop 0, 1, N times, N is the maximum
– Run the loop, 0, 1, N, a, N-1 • Path testing can not reveal wrong or missing
functions
• Path testing may not catch interface errors
• Boundary Testing
• Path testing can not catch data flow errors
• Path testing can not catch specification errors
• Validate path coverage is difficult
9/19/2001 © Ye Wu 25 9/19/2001 © Ye Wu 26
9/19/2001 © Ye Wu 27 9/19/2001 © Ye Wu 28
5
Predicate Expression Path Instrumentation
• Path Predicate expression – the set of path Instrument – to modify a program so that it
predicates associated with a path measures coverage while executing.
9/19/2001 © Ye Wu 31 9/19/2001 © Ye Wu 32