CS计算机代考程序代写 gui UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS
INFR10057 SOFTWARE TESTING
Monday 7 th May 2018 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: S.Rogers, A. Donaldson, S. Kalvala
THIS EXAMINATION WILL BE MARKED ANONYMOUSLY

1. THIS QUESTION IS COMPULSORY.
Consider the following specification: An array with an odd number of elements is said to be centered if all elements, other than the middle element, are strictly greater than the value of the middle element. Note that only arrays with an odd number of elements have a middle element. The function should accept an integer array as input and return 1 if it is a centered array, and return 0 otherwise. Consider the following function to implement the specification,
static int centered(int[] a)
{ int midIndex, middleItem;
if (a == null || a.length % 2 == 0) return 0;
midIndex = a.length / 2 ;
middleItem = a[midIndex + 1];
for (int i=0;
i= a[i])
(a) Identify the fault and suggest a correct solution. You will use this correct solution for the rest of the questions.
(b) Draw the control flow graph for the correct solution of the centered function. Label each of the edges in the control flow graph with a number and each of the blocks with a letter.
(c) Write 3 tests with input and expected output for this function. 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 in the above function. Explain your answer.
QUESTION CONTINUES ON NEXT PAGE
Page 1 of 6
} }
return 0;
return 1;
//Line 1
//Line 2
//Line 3
//Line 4
//Line 5
//Line 6
//Line 7
//Line 8
//Line 9
//Line 10
//Line 11
[2 marks]
[3 marks]
[3 marks]
[4 marks]

QUESTION CONTINUED FROM PREVIOUS PAGE
(e) Suppose the developer has incorrectly written the condition with || instead of && in the last if statement (in the correct solution) as
if(i ! = midIndex || middleItem >= a[i])
Will the tests you developed in the previous step reveal this fault?
Which coverage criteria is effective in revealing faults in complex boolean expressions? Develop tests that achieve 100% coverage of this criteria for the faulty expression shown. You can reuse tests developed for questions (c) and (d).
(f) Name the coverage criteria that is practical for testing paths through loops? For one of these criteria, compute coverage achieved using tests developed in previous parts,(c) and (d). If full coverage is not achieved, develop tests to achieve full coverage.
(g) For the corrected centered function, write tests with input and expected output that achieves “All DU pairs” coverage. Write out the “D,U” pairs for the variables in the function (using the line numbers shown) and show coverage achieved.
[4 marks]
[4 marks]
[5 marks]
Page 2 of 6

2. You should either answer this question or question 3.
Assume we have an application that accepts inputs using the following GUI control elements: 2 check boxes, 1 radio buttons, and one text box. Below are the values that each one of the GUI objects can take,
• Check Box – Checked or Unchecked
• Radio Button – ON or OFF
• Text Box – Any number between 1 and 100
(a) How many tests do you need to exhaustively test the input space?
(b) Define partitions/value classes for the inputs. How many test specifications do you get covering all combinations of the value classes for all inputs?
(c) Generate test case specifications for pairwise testing of the different inputs.
(d) Give concrete test cases for each of the test case specifications. If you have more than 10 test case specifications, select 10 test case specifications and provide a maximum of 10 tests covering all of them.
(e) What is an equivalent mutant? For the following program, create three mu- tants using three different types of mutation operators. One of the mutants should be equivalent. Name the type of mutation operators used. Write a single test and compute the mutation score achieved when it is executed.
public static void bubblesort(int[] list){
int temp;
boolean changed = true;
if (list == null || list.length == 0)
System.out.println(“Invalid list of numbers.”)
for(int i = 0; i < list.length && changed; i++) { changed = false; [2 marks ] [4 marks ] [6 marks] [3 marks ] [6 marks ] for(int j = 0; j < list.length - i - 1; j++) { if(list[j] > list[j+1])
{ changed = true;
temp = list[j + 1];
list[j + 1] = list[j];
list[j] = temp;
} }
(f) Why is regression testing time consuming? Describe techniques available to optimise regression testing.
Page 3 of 6
} }
[4 marks ]

3. You should answer either this question or question 2.
(a) Draw a context sensitive call graph for the following class. Only consider
functions defined in the class for the call graph.
public class Complex {
double real;
double imag;
public Complex(double real, double imag) {
this.real = real;
this.imag = imag;
}
public static void main(String[] args) {
Complex n1 = new Complex(2.3, 4.5),
n2 = new Complex(3.4, 5.0),
temp;
temp = add(n1, n2);
[3 marks]
System.out.printf(“Sum = %.1f + %.1fi”, temp.real, temp.imag);
}
public static Complex add(Complex n1, Complex n2)
{
Complex temp = new Complex(0.0, 0.0);
temp.real = n1.real + n2.real;
temp.imag = n1.imag + n2.imag;
return(temp);
}
}
(b) A system has a failure rate of 4 × 10−3 failures/hours. What is the Mean Time to Failure (MTTF) or Expected Life?
(c) A component has a failure rate of 5 failures/106 hours. What is the reliability of the component after 10,000 hours of operation?
QUESTION CONTINUES ON NEXT PAGE
Page 4 of 6
[2 marks] [2 marks]

18
19
20
21
22
23 }
24 }
for (int i = 0;
i < m; i++) System.out.print(perm[i] + " "); System.out.println(); QUESTION CONTINUED FROM PREVIOUS PAGE (d) Show reach equations (used for computing reaching definitions) for line 16 using reach and reachout equations for lines 15, 14 and 13 of the following method, public class Sample { public static void main(String[] args) { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 } int m = Integer.parseInt(args[0]); int n = Integer.parseInt(args[1]); // create permutation 0, 1, ..., n-1 int[] perm = new int[n]; for (int i = 0; i < n; i++) perm[i] = i; // choose this many elements // from 0, 1, ..., n-1 // create random sample in perm[0], perm[1], ..., perm[m-1] for(inti=0; i< m; i++) { // random integer between i and n-1 int r = i + (int) (Math.random() * (n-i)); // swap elements at indices i and r int t = perm[r]; perm[r] = perm[i]; perm[i] = t; (e) Briefly describe three security vulnerabilities. Why are traditional testing techniques inadequate for ensuring software security? Briefly describe two testing techniques for security requirements. QUESTION CONTINUES ON NEXT PAGE Page 5 of 6 [4 marks] [5 marks] QUESTION CONTINUED FROM PREVIOUS PAGE (f) 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 an integer number as input. Spec 1: If input is negative print "error". Spec 2: Print the word "fizz" if the number is a multiple of 5. Spec 3: Print the word "buzz" if the number is a multiple of 7. Spec 4: Print the word "fizzbuzz" if the number is a multiple of both 5 and 7. Spec 5: Print the number if it is not a multiple of 5 or 7. [9 marks] Page 6 of 6