Possible Solutions for the First Computer Science 316 Exam Spring, 1999 1. Develop a test set for the module below. Use one of the two white box testing methods: Data Flow or Domain Testing. Here is the program with lines numbered for reference and comments removed ( since they don't affect the testing ): 1 #include 2 #include 3 arrsort ( int a[10]) 4 { 5 const int arraySize = 10; 6 int hold; 7 cout << "Data items in original order" << endl; 8 for (int i = 0; 9 i < arraySize; 10 i++) 11 cout << setw(4) << a[i]; 12 for ( int pass = 1; 13 pass < arraySize; 14 pass++) 15 for ( i = 0; 16 i < arraySize - 1; 17 i++) 18 if (a[i] > a[i + 1] { 19 hold = a[i]; 20 a[i] = a[ i + 1 ]; 21 a[ i + 1 ] = hold; 22 } 23 cout << endl << "Data items in ascending order" << endl; 24 for ( i = 0; 25 i < arraySize; 26 i++) 27 cout << setw(4) << a[i]; 28 cout << endl; 29 return 0; 30 } Let's start by considering Data Flow Testing. This module has the following variables: 1. a 2. arraySize ( actually a constant and you could leave it out) 3. i 4. pass 5. hold Here are the DU-chains for each variable: a a. 3 - 11 b. 3 - 18 c. 3 - 19 d. 3 - 20 e. 3 - 21 f. 3 - 27 g. 20 - 18 h. 20 - 19 i. 20 - 20 j. 20 - 21 k. 20 - 27 arraySize l. 5 - 9 m. 5 - 13 n. 5 - 16 o. 5 - 25 i p. 8 - 9 q. 8 - 10 r. 8 - 11 s. 10 - 9 t. 10 - 10 u. 10 - 11 v. 15 - 16 w. 15 - 17 x. 15 - 18 y. 15 - 19 z. 15 - 20 aa. 15 - 21 ab. 17 -16 ac. 17 - 17 ad. 17 - 18 ae. 17 - 19 af. 17 - 20 ag. 17 - 21 ah. 24 - 25 ai. 24 - 26 aj. 24 - 27 ak. 26 - 25 al. 26 - 26 am. 26 - 27 pass an. 12 - 13 ao. 12 - 14 ap. 14 - 13 aq. 14 - 14 hold ar. 19 - 21 We can exercise all of these DU-chains with a single test case in which the first element of the array is out of order and another element is also out of order. Here is a possible test set: Input: a = { 4, 2, 5, 7, 8, 9, 11, 5, 9, 12 } Expected Output: Data Items in Original Order 4 2 5 7 8 9 1 5 9 12 Data Items in ascending order 1 2 4 5 5 7 8 9 9 12 The question also gives the option of using Domain Testing. Domain testing considers only the relational expressions. In this module, there are relational expressions in statements: 9, 13, 16, 18, and 25. For each relational expression, we need to use values of the two arguments that cause them to have each of the relationships less than, equal, and greater than. Further our cases for less than and greater than should be as close to equal as possible. The relational expressions in statements 9, 13, 16 and 25 are not affected by input data. Hence we can create test cases only for the relational expression in statement 18. We need to have situations where a[i] is less than, equal to, and greater than a[i+1]. In the less than and greater than situations, the two array values should differ by only 1 ( the smallest amount possible in this case). We can do all of this in one test case. Here is a possible test set: Input: a = { 4, 3, 3, 4, 6, 2, 7, 8, 9, 11 } Expected Output: Data Items in Orginal Order 4 3 3 4 6 2 7 8 9 11 Data Items in ascending order 2 3 3 4 4 6 7 8 9 11 Notice that all the necessary tests occur with just the first four items of the array - the rest of the array input is arbitrary. 2. Develop a test set for the module requirements description given. Use one of the two black box testing methods: Weak Equivalence Class Partitioning or Weak Boundary Value Analysis. Let's start with Weak Boundary Value Analysis. The inputs for the test cases come solely from the information about the ranges of valid inputs. In this case, we need the following input values: 1. Child's age: -1, 0, 121, 122 2. Weight: 4, 5, 120, 121 3. Temperature: 94.9, 95, 105, 105.1 Thus, for weak boundary value analysis, we need only four test cases. Here is one possible test set: 1. Input: -1, 4, 94.9 Expected Output: error 2. Input: 0, 5, 95 Expected Output: no medication 3. Input: 121, 120, 105 Expected Output: any medication, 3 teaspoons every four hours. 4. Input: 122, 121, 105.1 Expected Output: error. Weak Equivalence class partitioning is more complicated. We have the following equivalence classes: 1. Temperature less than 95 degrees, temperature between 95 and 99.5 degrees, temperature between 99.5 and 105 degrees, temperature greater than 105 degrees. 2. age less than 0, age between 0 and 40 months, age between 40 and 72 months, age between 72 and 121 months, age greater than 121 months. 3. weight less than 5 pounds, weight between 5 and 35 pounds, weigth more than 35 pounds, but less than 120 plus pounds, weight greater than 120 pounds. We can choose any values in each of those ranges, for example, 1. 90, 97.3, 101.1, 107.4 2. -3, 24, 55, 77, 200 3. 3, 22, 55, 155. Here again, we would have five test cases in our test set, for example, 1. Input: 90, -3, 3 Expected Output: error 2. Input: 97.3, 24, 22 Ex[ected Output: no medication 3. Input: 101.1, 55, 55 Expected Output: any medication, 4/5 teaspoon. 4. 107.4, 77, 155 Expected Output: error 5. 97.3, 200, 155 Expected Output: error. 3. Answer only one of a or b. a. Describe the difference between validation and verification. In what ways do each make use of testing strategies and test cases? Verification is the set of activities that ensure the software implements a given function correctly. Validation is the set of activities that ensure the software implements the correct functions ( those derived from the user requirements). Verification would depend primarily on white box testing. Validation would depend primarily on black box testing. Both should be part of any testing strategy. b. Why is rapid cycle testing desirable? Rapid cycle testing involves testing small portions of the overall product ( typically about 2%) each time and providing detailed feedback on faults found within one week each time. Each part of this description provides an advantage. By testing small portions of the product, it is much easier to be more comprehensive and the debugging and repair processes are much simpler and less error-prone. By providing rapid feedback, the testers are able to influence the developers throughout the coding portion of development.