Software Testing and Quality Assurance Assignment: Exercise 1
Software Testing and Quality Assurance Assignment: Exercise 1
Exercise 1
Assume following specification for some piece of code which could be part of a bisection
algorithm to find π/2:
Input parameters are the float values a and b.
Swap a and b unless a <= b.
Set a and b to 1 and 3 unless cos(a) >= 0 or cos(b) <= 0.
Set x to the arithmetic mean of a and b.
Set a to x if cos(x) > 0 and b to x otherwise.
Print a and b.
This is the code:
1. if (a > b) {
2. float tmp(b); b = a; a = tmp;
3. }
4. if (cos(a) < 0 || cos(b) > 0) {
5. a = 1; b = 3;
6. }
7. x = (a + b) / 2;
8. if (cos(x) > 0) {
9. a = x;
10. } else {
11. b = x;
12. }
Write test cases that are able to cover the following situations:
(A) swap code at line 2
(B) line 2 is not executed
(C) line 5 is executed
(D) line 5 is not executed
(E) line 9 is executed
(F) Line 11 is executed
Exercise 2
Consider the following requirements and code:
The program shall take as input an array of three integer numbers.
The program shall output the greatest number among the elements of the array.
The program shall order the elements of the array in decreasing order.
1. public int[] order(int v[]) {
2. int tmp;
3. if (v[0]<v[1]) {
4. tmp = v[0];
5. v[1] = v[1];
6. v[1] = tmp;
7. }
8. if (v[1]<v[2]) {
9. tmp = v[0];
10. v[1] = v[2];
11. v[2] = tmp;
12. }
13. return v;
14. }
A. Draw a data flow graph for the binsearch() function given above
B. Assuming that the input arrayV[] has at least one element in it, find an infeasible path in
the data flow graph for the binsearch() function.
C. Find a set of complete paths satisfying the all-defs selection criterion with respect to
variable mid.
D. Find a set of complete paths satisfying the all-defs selection criterion with respect to
variable high.
1. int modifiedbinsearch(int X, int V[], int n){
2. int low, high, mid;
3. low = 0;
4. high = n - 1;
5. while (low <= high) {
6. mid = (low + high)/2;
7. if (X < V[mid]) {
8. high = mid - 1;
9. mid = mid - 1;
10. }
11. else if (X > V[mid])
12. low = mid + 1;
13. else
14. return mid;
15. }
16. return -1;
17. }