Mandatory assignment #2 05-04-2005 Kenn A. Thisted * Consider the following problem: "Given 3 arguments x, y and z return the middle one" Define a structural test for each of the two implementations below as well as a functional test. Kenn 05-04-2005: Prerequisite: If two (or all three) values are equal, it is valid to return any one of these as the middle value. 1. The first implementation consists of one function: public int middle(int x, int y, int z) { if( x < y && x < z ) /* 1 */ { if( y < z ) return y; /* 2 */ return z; } if( y < x && z < x ) /* 3 */ { if( y < z ) return z; /* 4 */ return y; } return x; } Structural test 1 (two tables): ---------------------------------------------------------------------------- | Choice | Input data set | Input property | ---------------------------------------------------------------------------- | 1 true | A | x < y and x < z | | 1 false | B | x < y and x >= z | | 1 false | D | x >= y (second condition not evaluated) | | 2 true | A | x < y and x < z and y < z | | 2 false | C | x < y and x < z and y >= z | | 3 true | D | y < x and z < x | | 3 false | E | y < x and z >= x | | 3 false | A | y >= x (second condition not evaluated) | | 4 true | D | y < x and z < x and y < z | | 4 false | F | y < x and z < x and y >= z | ---------------------------------------------------------------------------- ---------------------------------------------------- | | Contents | | | Input data set | x y z | Expected output | ---------------------------------------------------- | A | 1 11 21 | 11 | | B | 12 22 2 | 12 | | C | 3 23 13 | 13 | | D | 24 4 14 | 14 | | E | 15 5 25 | 15 | | F | 26 16 6 | 16 | ---------------------------------------------------- Functional test 1 (two tables): ---------------------------------------------------- | Input data set | Input property | ---------------------------------------------------- | A1 | (Middle, low, high) | | A2 | (Middle, high, low) | | B1 | (Low, middle, high) | | B2 | (High, middle, low) | | C1 | (Low, high, middle) | | C2 | (High, low, middle) | | D1 | (Equal, equal, MAX_VALUE) | | D2 | (Equal, equal, MIN_VALUE) | | E1 | (MAX_VALUE, -equal, -equal) | | E2 | (MIN_VALUE, -equal, -equal) | | F1 | (Zero, MAX_VALUE, zero) | | F2 | (Zero, MIN_VALUE, zero) | | G | (Equal, equal, equal) | ---------------------------------------------------- ---------------------------------------------------- | | Contents | | | Input data set | x y z | Expected output | ---------------------------------------------------- | A1 | 11 1 21 | 11 | | A2 | 12 22 2 | 12 | | B1 | 3 13 23 | 13 | | B2 | 24 14 4 | 14 | | C1 | 5 25 15 | 15 | | C2 | 26 6 16 | 16 | | D1 | 57 57 MAX | 57 | | D2 | 67 67 MIN | 67 | | E1 | MAX -78 -78 | -78 | | E2 | MIN -88 -88 | -88 | | F1 | 0 MAX 0 | 0 | | F2 | 0 MIN 0 | 0 | | G | 42 42 42 | 42 | ---------------------------------------------------- MAX = Integer.MAX_VALUE MIN = Integer.MIN_VALUE 2. The second implementation consists of two functions: public int least(int a, int b) { if( a < b ) return a; /* 1 */ return b; } public int middle(int x, int y, int z) { m = least(y,z); if( x < m ) return m; /* 2 */ m = least(x,z); if( y < m ) return m; /* 3 */ return least(x,y); } Structural test 2 (three tables): ---------------------------------------------------------------------------- | Choice | Input data set | Input property | ---------------------------------------------------------------------------- | 1 true | X | a < b | | 1 false | Y | a >= b | | | | | | 2 true | A | x < y and x < z (y = a and z = b) | | 2 false | B | x < y and x >= z - | | 2 false | D | x >= y and not eval. - | | 3 true | E | y < x and y < z (x = a and z = b) | | 3 false | F | y < x and y >= z - | | 3 false | C | y >= x and not eval. - | ---------------------------------------------------------------------------- (missing link from a,b to m in y,z or x,z format - how to show properly?) ---------------------------------------------------- | | Contents | | | Input data set | a b | Expected output | ---------------------------------------------------- | X | 11 21 | 11 | | Y | 22 12 | 12 | | Y' (here?) | 23 23 | 23 | ---------------------------------------------------- ---------------------------------------------------- | | Contents | | | Input data set | x y z | Expected output | ---------------------------------------------------- | A | 1 11 21 | 11 | | B | 12 22 2 | 12 | | C | 3 23 13 | 13 | | D | 24 4 14 | 14 | | E | 15 5 25 | 15 | | F | 26 16 6 | 16 | ---------------------------------------------------- Functional test 2: As the "problem" is the same in both implementations the functional test of the first problem should suffice for this second problem as well. * Select a part of your previously handed in assignment and J2MEUnit test it. Try to select an isolated functionality; if your program does everything in one method, you are allowed to move a piece of functionality to a separate method in order to test it. Do not test to much. Complete testing is an infinite amount of work. Your goal is to demonstrate that you can implement into the J2MEUnit framework, and do a reasonable test. You should be able to accomplish that with around 5 assertions. I chose to show testing of a couple of the navigation methods (zoomIn() and zoomOut()) in Plot.java. This in my opinion demonstrates the assignment objective, knowing that real life testing should cover in this particular case the remaining navigation methods as well as could for the chosen methods also cover for example an odd (uneven) x-range by testing with a yValues set of 3 and/or 5 elements. > see enclosed itu_jma_mandass2_kenn_thisted.zip