UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS
INFR10057 SOFTWARE TESTING
Thursday 4 th May 2017 09:30 to 11:30
INSTRUCTIONS TO CANDIDATES
Answer QUESTION 1 and ONE other question. QUESTION 1 is COMPULSORY.
All questions carry equal weight.
This is an OPEN BOOK examination.
You may consult any books or other documents during this examination.
The use of Calculators is permitted.
Year 3 Courses
Convener: C. Stirling
External Examiners: A. Cohn, A. Donaldson, S. Kalvala
THIS EXAMINATION WILL BE MARKED ANONYMOUSLY
1. THIS QUESTION IS COMPULSORY.
The specification for a program requires the decimal representation of an input number to be reversed and returned if the input number is positive. If the input number is negative, the program should return the absolute value of this input number (without reversing). Consider the following method to implement the specification
public int reverse_number(int num)
{
int reversenum = 0;
while( num != 0 )
//Line 1
//Line 2
//Line 3
} }
{
reversenum = reversenum + num%10; //Line 5
reversenum = reversenum * 10;
//Line 4
//Line 6
//Line 7
num = num/10;
return reversenum;
(a) Identify the fault and suggest a correct solution.
[4 marks ]
[4 marks ]
[4 marks ]
[4 marks ]
[4 marks ]
[5 marks ]
(b) Draw the control flow graph for the corrected solution for reverse number method. Label each of the edges in the control flow graph with a number and each of the blocks with a letter.
(c) Write tests with input and expected output for the corrected method that does not execute the fault. Using the labels on the edges in the flow graph, write down the sequence of edges traversed by each of the tests. Edges that get traversed repeatedly as part of the loop only need to be written down once.
(d) Evaluate the fraction of edges covered by the tests (Covered/Total). If any edges are uncovered, write additional tests to cover them. Evaluate if the tests developed thus far will uncover the fault. Explain your answer.
(e) Nameatleasttwocoveragecriteriathatarepracticalfortestingpathsthrough loops. For one of these criteria, compute coverage achieved using tests de- veloped in previous parts (c) and (d). If full coverage is not achieved, develop tests to achieve full coverage.
(f) For the faulty reverse number method given above, write tests with input and expected output that achieves ¡°All DU pairs¡± coverage. Write out the < D,U > pairs for the variables in the method (using the line numbers shown) and show coverage achieved.
Page 1 of 4
2. You should either answer this question or question 3.
Let¡¯s say we¡¯re asked to test a function area(int n) which calculates the Area of a Square with side provided as parameter n. The function returns the area if n is positive, returns 0 for negative inputs and -1 when the result is out of range: int area(int n)
(a) Assume the method area(int n) is the ITF (Independently Testable Fea- ture) – ¡°correctly computes and returns the area of a square with side pro- vided by parameter, n, or returns an appropriate error code.¡± What are the characteristics of the input and environment?
(b) Define partitions/value classes for the input and environment based on the characteristics.
(c) Generate test case specifications for the different value classes, giving ex- pected results.
(d) Give concrete test cases for each of the test case specifications with expected result. If you have more than 10 test case specifications, select 10 test case specifications and provide a maximum of 10 tests covering each of them.
[5 marks] [6 marks] [7 marks]
[7 marks]
Page 2 of 4
3. You should either answer this question or question 2.
(a) Explain the steps in the Test-Driven Development process. What are the
benefits of using TDD?
(b) For the following specification, illustrate steps involved in TDD. As part of the steps, the code that you write can be in the form of pseudo-code or a programming language of your choice. For the purpose of the exam, do not worry about the syntactical correctness of the code. You only need to focus on program logic and its correspondence to tests developed.
Take two integer numbers as inputs,
Spec 1: If both input numbers are positive,
compute and return the sum.
Spec 2: If both input numbers are negative, return zero.
Spec 3: If one input is positive and the other is negative,
return positive number.
Spec 4: If both input numbers are zero, return -1.
(c) A fault-free system is failure-free but a failure-free system need not be fault- free. Using the technical sense of fault and failure, explain this statement and give an assessment of whether it is true or false.
(d) Compute reaching definitions at Line 7 of the following method,
[4 marks]
public int check_prime(int a)
{
int c;
if ( a ==0 || a ==1)
return 0;
// Line 1
// Line 2
// Line 3
// Line 4
// Line 5
// Line 6
// Line 7
// Line 8
// Line 9
// Line 10
// Line 11
}
for (
{
c=2; c<=a-1; c++){
(a%c==0) return 0;
if
}
if ( (c == a) && (a%10 == 7) )
return 1;
return 0;
QUESTION CONTINUES ON NEXT PAGE
Page 3 of 4
[10 marks]
[4 marks]
QUESTION CONTINUED FROM PREVIOUS PAGE
Show the Reach equations for Line 7. Iterate once and show the Reach equations for this iteration. How are Reach equations different from Avail equations?
(e) Arrays and pointers introduce uncertainty into data flow analysis. Explain why this is the case.
[5 marks] [2 marks]
Page 4 of 4