Presentation is loading. Please wait.

Presentation is loading. Please wait.

Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks.

Similar presentations


Presentation on theme: "Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks."— Presentation transcript:

1 Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks

2 Statement coverage To get 100% statement coverage, we need to execute every statement. The initial value x=2 will execute the body of the while loop, going into the then part of the first if statement and the else part of the second. The initial value x=3 will go into the body of the while loop, and execute the else part of the first if statement and the then part of the second if statement. Therefore, the two test cases, x=2 and x=3 will give us statement coverage. You might think that this is one of the possible choices for a smallest test data set, since no test case can possibly contain fewer than two test cases. That is, where there is a if then else statement, we know we need at least two test cases. However, the if statement is inside a while loop, so we can try to choose a test case that will cover both branches, by choosing one that covers different branches each time round the while loop. We might try just the single test case x=3. This makes the program fail to terminate, but it does cover all the statements. (5 marks)

3 Branch coverage We know that any test set which achieves branch coverage will achieve statement coverage, but not necessarily the other way round: a test set which can achieve 100% statement coverage may not achieve 100% branch coverage. In the case of the while loop in this question, we certainly need to cover every (at least) branch in the body of the loop. We might hope that this is achieved with the test set which we just developed for statement coverage, since the if- then-else statements have statements on each branch. However, there is one branch we still have not yet covered with these two test cases: we did not cover the branch which simply exits the while loop without going into the body at all. To do this, we must add another test case, to make the while loop condition initially false. For example x=1 would do this. The result is a minimal test set, because we know we need the original test case ( x=3 ) to cover the branches in the body of the loop and we must have one more to avoid the body all together. If we could find a test case that entered the loop and when round all branches ion the body and then executed the loop, then we would be able to cover all branches with a single test case. However, in this case I believe that there is no such test case. That is, if you enter the loop, I think that you can never exit the loop. I would be very interested if a student was able to find a single value that covered all branches. (5 marks)

4 L | S / \ C C / \ / \ A A Coursework 1 Q1 – Solution (a) Tree – (5 marks) CFG – (5 marks) L 7 | S 6 / \ C 3 C 3 / \ / \ A 1 A 1 Calculation – (3 marks) Tree does not need to be drawn twice

5 Structure: L(S(C(A,A),C(A,A))) Calculation of LOC: M(L(S(C(A,A),C(A,A)))) = M(S(C(A,A),C(A,A))) + 1 = M(C(A,A)) + M(C(A,A)) + 1 = (M(A)+ M(A)+1) + (M(A)+M(A)+1) + 1 = ( ) + ( ) + 1 = 7 Coursework 1 Q1 – Solution (a) Alternative presentation of tree and calculation:

6 Visit each loop measure (5 marks) V(A) = 1 V(C(p1,p2)) = M(p1) + M(p2) V(L(p1)) = M(p1) + 1 V(S(p1,p2)) = M(p1) * M(p2) Calculation (2 marks) (could also be presented as a tree as in part a) V(L(S(C(A,A),C(A,A)))) = V(S(C(A,A),C(A,A))) + 1 = V(C(A,A)) * V(C(A,A)) + 1 = (V(A) + V(A)) * (V(A) + V(A)) + 1 = (1 + 1) * (1 + 1) + 1 = 5 Coursework 1 Q1 – Solution (b)

7 For the visit each loop strategy,what is the largest number of tests which could be required for 100% coverage of a program of 7 lines of code. The largest number of paths is produced by sequencing. The units sequenced together must be loops or conditionals. Conditionals require 3 LOC but loops only 2 LOC. Note for 3 lines maximise with L(L(A)) – 3 paths for 4 lines L(L(L(A))) or (L(A));(L(A)) – 4 paths for 5 lines (L(A));(L(L(A))) – 6 paths for 6 lines (L(L(A)));(L(L(A))) – 9 paths > 2^3 for 7 lines (L(L(L(A))));(L(L(A))) – 4*3 = 12 paths Max number of tests for 7 LOC is 12 (5 marks) if incorrect: give 1 marks for each point of correct reasoning Coursework 1 Q1 – Solution (c)

8 Give a formula in $n$, the number of lines of code, which expresses the maximum number of tests which could be required for 100\% coverage with this strategy. (5 marks) – If incorrect give 1 mark for each point below In general, candidates for the worst case code are: L(A);L(A);L(A);.... or L(L(A));L(L(A));L(L(A));... These give functions (for n lines of code) approximately: 2^(n/2) or 3^(n/3) Now the latter is larger since (let n = 6m) 2^(n/2)= 2^(3m)= (2^3)^m = 8^m 3^(n/3)= 3^(2m)= (3^2)^m = 9^m So choose series of L(L(A)) in sequence, but if you have 1 line to spare use L(L(L(A))) once, if you have 2 line to spare add an extra L(A). The exact formulation is: maxtests(n) = 3^(n/3) if n mod 3 = 0 maxtests(n) = 3^(n-4/3)*4 if n mod 3 = 1 maxtests(n) = 3^(n-2/3)*2 if n mod 3 = 2 Coursework 1 Q1 – Solution (d)

9 Consider the following piece of pseudo-code: 1 n := in; 2 while (n > 1) do 3 if (n mod 2 = 0) then 4 n := n/2 else 5 n := 3*n+1 endif enddo; 6 out := n Coursework 1 Q2

10 a.Draw the Control Flowgraph for this code and annotate the nodes to indicate the definitions and uses of the variable n. b.Give all the du pairs for n and for each pair give a d-clear, simple path fragment which exercises it. c.The single input, n = 5, exercises many aspects of this program. Give the path taken for this input value and give the test case for this path. Define the term test coverage. What coverage of the above path fragments is achieved by the single test. d.Give some further test cases which maximise the du-path coverage and explain why it is impossible to achieve 100% coverage with the all du-paths strategy for this example.

11 1 n := in; 2 while (n > 1) do 3 if (n mod 2 = 0) then 4 n := n/2 else 5 n := 3*n+1 endif enddo; 6 out := n Coursework 1 Q2 – Solution (a) in out n u d u u u,d u,d du CFG - (5 marks) Annotations - (5 marks)

12 1 n := in; 2 while (n > 1) do 3 if (n mod 2 = 0) then 4 n := n/2 else 5 n := 3*n+1 endif enddo; 6 out := n Coursework 1 Q2 – Solution (b) in out n u d u u u,d u,d du 12 12Y Y N Y N Y Y Y N Y Y Y Y N N DU Pairs (5 marks) Paths Frags (5 marks) Coverage (part c)

13 Coursework 1 Q2 – Solution (c) The single input, n = 5, exercises many aspects of this program. Give the path taken for this input value and give the test case for this path. Define the term test coverage. What coverage of the above path fragments is achieved by the single test. Input 5 gives path: 1,2 5,3,5,2 16,3,4,2 8,3,4,2 4,3,4,2 2,3,4,2 1,6 (4 marks) Test case for this path is: input = 5, output = 1 (2 marks) Coverage defined to be that proportion of the items required to be exercised that are exercised by the test suite. (2 marks) Coverage here is 10 out of 15 i.e. 66%. (2 marks)

14 Coursework 1 Q2 – Solution (d) Give some further test cases which maximise the du-path coverage and explain why it is impossible to achieve 100% coverage with the all du-paths strategy for this example. Other tests (outputs always = 1) any even input – path (2 marks) input = 1 – path 126 (2 marks) input = 3 – path 1,2 3,, 3,5,2 10, 3,4,2 5 …(includes 4,2,3,5) (2 marks) path fragment 5235 is infeasible as odd never results in even next time around ie. 3n+1 cannot be odd (2 marks) path fragment 526 is infeasible as odd never results in 1 next time around ie 3n+1 cannot = 1 (2 marks)

15 Coursework 1 Q3 See solutions in tutorial four. 1. state cover: 2 marks 2. characterizing set 3 marks 3. a set of sequences that execute each transition 5 marks 4. a transition tour 2 marks 5. a set of sequences that contain each transition followed by sequences that check its final state 8 marks


Download ppt "Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks."

Similar presentations


Ads by Google