1 / 9

Coursework 1

Coursework 1. Due Tuesday, Feb 6, 2007 in the tutorial Comprises two questions Each question was expected to take 40 minutes in exam conditions. Coursework Question 1. An example program in this language is: while(x > 1) do if (x mod 2 == 0) then x := x/2 else x := x * 2 endif ;

newmanj
Download Presentation

Coursework 1

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. Coursework 1 • Due Tuesday, Feb 6, 2007 in the tutorial • Comprises two questions • Each question was expected to take 40 minutes in exam conditions

  2. Coursework Question 1 An example program in this language is: while(x > 1) do if (x mod 2 == 0) then x := x/2 else x := x * 2 endif ; if (x mod 3 == 0) then x := x/3 else x := x * 3 endif enddo For a simple language with: assignments (A), binary conditionals (C), loops (L), and sequencing (S); a measure, M , for “lines of code" can be defined hierarchically as follows (where p1 and p2 are sections of the program): • M(A) = 1 • M(C(p1; p2)) = M(p1) +M(p2) + 1 • M(L(p1)) = M(p1) + 1 • M(S(p1; p2)) = M(p1) +M(p2)

  3. Coursework 1, Question 1 continued Test data for this simple program is an initial value for x. Give test data to achieve 100% statement coverage. Give test data to achieve 100% branch coverage Make these two sets of test data as small as possible. (a) Give the structure as a tree of the given program fragment and draw the control flowgraph for it. Use the above definition to calculate (showing working) the number of lines of code. (b) The “visit each loop" strategy executes all combinations of possible outcomes of decisions at conditionals and loops. Loops are not required to be executed more than once. Define a measure for the maximum number of tests required by this strategy and calculate its value (again showing working) for the given program fragment. (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. 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.

  4. Coursework 1, Question 1c, hint 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 maximize 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 calculate the maximum number of tests for 6 lines and 7 lines by yourself. In general, candidates for the worse case code are: 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) (3^(n/3) is larger, why?) So, maxtests(n) = 3^(n/3) if n mod 3 = 0 maxtests(n) = ?? if n mod 3 = 1 maxtests(n) = ?? if n mod 3 = 2 You have to answer the question marks part.

  5. Coursework 1, Question 2 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

  6. Coursework 1, Question 2 continued • 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.

  7. Coursework 1, Question 3 • This question consists of questions 1 and 2 applied to machine M2 on the following two pages.

  8. 2) For state machines M2 above, use the sets derived in part 1) to produce the following: i.                  a set of sequences that execute each transition ii.                 a transition tour iii.               a set of sequences that contain each transition followed by sequences that check its final state 3) For each FSM in part 1) that has a UIO for each state, produce a tour that includes a test subsequence for each transition. That is, you need to follow each transition and then check (with a UIO) that the right final state is reached.

More Related