UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS
INFR10057 SOFTWARE TESTING
Friday 13 th May 2016 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 text book or printouts of book chapters during this examination.
CALCULATORS MAY NOT BE USED IN THIS EXAMINATION.
Year 3 Courses
Convener: C. Stirling External Examiners: A. Cohn, T. Field
THIS EXAMINATION WILL BE MARKED ANONYMOUSLY
1. Students MUST answer this question
Consider the following method that checks if a given number is prime and if the number has 7 as its units digit. The method returns 1 if the argument is prime and ends in 7, and 0 otherwise.
public int check_prime(int a)
{
int c;
if ( a ==0 || a ==1)
return 0;
for ( c = 2 ; c <= a - 1 ; c++ )
{
if ( a%c == 0 )
return 0;
}
if ( (c == a) && (a%10 == 7) )
return 1;
return 0; }
(a) Draw the control flow graph for the check prime method. Label each of the edges in the control flow graph with a number and each of the blocks with a letter.
(b) Write tests with the input and expected output for this method. 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.
(c) Evaluate the fraction of edges covered by the tests (Covered/Total). If any edges are uncovered, write additional tests to cover them.
(d) Suppose the developer has incorrectly written the condition with || instead of && in the last if statement as if ((c == a) || (a%10 ==7)). Will the tests you developed in the previous step reveal this fault? Explain your answer.
(e) Which coverage criterion is both practical and rigorous for testing com- plex boolean expressions? For the expression ((x1 || y1) && z1), develop tests that achieve this coverage criterion. Assume x1, y1, z1 are all in- put boolean variables. Each of your tests should assign values to the input boolean variables and evaluate the expression.
Page 1 of 5
[4 marks ]
[4 marks ] [2 marks ]
[3 marks ]
[6 marks ]
(f) For the check prime method, write tests with input and expected output that achieves ¡°All DU pairs¡± coverage for variable c. Write out the < D, U > pairs for the variable c and show coverage achieved.
[6 marks]
Page 2 of 5
2. Let¡¯s say we¡¯re asked to test a function which calculates the factorial (n!) of a number n, returning 0 for negative inputs and -1 when the result is out of range: int factorial (int n)
(a) Assuming the factorial method is the ITF (Independantly Testable Feature)- ¡°correctly computes and returns the factorial of its parameter, n, or returns an appropriate error code.¡± What are the characteristics of the input and environment for this ITF?
(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 result.
(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 3 of 5
3. Consider the following method that checks if a given character (in the argument) is a vowel. The method returns 1 if the argument is a vowel, and 0 otherwise.
1 public int check_vowel(char a) 2{
3 4
5 6
7 8}
(a)
(b)
if (a >= ¡¯A¡¯ && a <= ¡¯Z¡¯)
a = a + ¡¯a¡¯ - ¡¯A¡¯; /* Converting to lower case */
if (a == ¡¯a¡¯ || a == ¡¯e¡¯ || a == ¡¯i¡¯ || a == ¡¯o¡¯ || a == ¡¯u¡¯)
return 1;
return 0;
For the check vowel method above, derive 6 mutations that perform ex- pression/operand modifications. Lines in the method above are marked. To show each mutation, simply state the line number being mutated and show the line with the modification.
Derive tests that reveal these modifications (one at a time, assuming each mutation results in a new method). Please show expected and actual output for each of the tests. Some mutations result in equivalent programs and cannot be revealed. If you have such equivalent mutants, point them out. Note: Decimal equivalent of characters range from 0 to 255. For characters ¡¯A¡¯ to ¡¯Z¡¯, decimal equivalent is 65 to 90. For ¡¯a¡¯ to ¡¯z¡¯ it is 97 to 122. You will not need to use these decimal equivalents, it is only provided here for better understanding.
[6 marks]
[6 marks]
Page 4 of 5
(c) The user has changed his/her mind about the specification and would now like to check for all vowels except u. The user would also like to check for the character r in addition to the vowels. The changed code is presented below. State which of the tests derived previously pass on the changed code and which of them fail. Use the expected output derived in the previous question to determine if they pass or fail. If they fail, state why.
1 public int check_vowel(char a) 2{
[4 marks]
3 4
5 6
7 8}
if (a >= ¡¯A¡¯ && a <= ¡¯Z¡¯)
a = a + ¡¯a¡¯ - ¡¯A¡¯; /* Converting to lower case */
if (a == ¡¯a¡¯ || a == ¡¯e¡¯ || a == ¡¯i¡¯ || a == ¡¯o¡¯ || a == ¡¯r¡¯)
return 1;
return 0;
(d) Write new tests to exercise the changed code.
(e) In which testing activity are global properties, such as performance and security, that involve interactions between the system and the environment tested? Describe one method for testing such properties.
[4 marks]
[5 marks]
Page 5 of 5