1 / 15

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

Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks. Statement coverage. To get 100% statement coverage, we need to execute every statement.

uma-ashley
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Marking Schemaquestion1: 40 marksquestion2: 40 marksquestion3: 20 markstotal: 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. Coursework 1 Q1 – Solution (a) CFG – (5 marks) Calculation – (3 marks) Tree – (5 marks) L7 | S6 / \ / \ C3 C3 / \ / \ A1 A1 A1 A1 L | S / \ / \ C C / \ / \ A A A A Tree does not need to be drawn twice

  5. Coursework 1 Q1 – Solution (a) Alternative presentation of tree and calculation: 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 + 1 + 1) + (1 + 1 + 1) + 1 = 7

  6. Coursework 1 Q1 – Solution (b) 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

  7. Coursework 1 Q1 – Solution (c) 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

  8. Coursework 1 Q1 – Solution (d) 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

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

  10. Coursework 1 Q2 • Draw the Control Flowgraph for this code and annotate the nodes to indicate the definitions and uses of the variable n. • Give all the du pairs for n and for each pair give a d-clear, simple path fragment which exercises it. • 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. • 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. Coursework 1 Q2 – Solution (a) in out n u d u u u,d u,d d u Annotations - (5 marks) CFG - (5 marks) 1 n := in; 2 while (n > 1) do • if (n mod 2 = 0) then 4 n := n/2 else 5 n := 3*n+1 endif enddo; 6 out := n

  12. Coverage (part c) Paths Frags (5 marks) DU Pairs (5 marks) Coursework 1 Q2 – Solution (b) in out n u d u u u,d u,d d u 12 12 Y 13 123 Y 14 1234 N 15 1235 Y 16 126 N 42 42 Y 43 423 Y 44 4234 Y 45 4235 N 46 426 Y 52 52 Y 53 523 Y 54 5234 Y 55 5235 N 56 526 N 1 n := in; 2 while (n > 1) do • if (n mod 2 = 0) then 4 n := n/2 else 5 n := 3*n+1 endif enddo; 6 out := n

  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,25,3,5,216,3,4,28,3,4,24,3,4,22,3,4,21,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 1234.... (2 marks) • input = 1 – path 126(2 marks) • input = 3 – path 1,23,,3,5,210 ,3,4,25…(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

More Related