40 likes | 152 Views
Path Testing. Class Activity. Path Testing. Bubble sort is well-known sorting algorithm. It starts by comparing each pair of adjacent elements from the beginning of an array and, if they are in reversed order, they are swapped.
E N D
Path Testing Class Activity
Path Testing Bubble sort is well-known sorting algorithm. It starts by comparing each pair of adjacent elements from the beginning of an array and, if they are in reversed order, they are swapped. If at least one swap has been done, the first step is repeated, otherwise the sorting is stopped.
Exercise Using the following Java source code for the bubble sort algorithm: • Draw the flow graph • Identify the number of independent paths • Write test cases for the bubble sort algorithm using path testing.
publicvoidbubbleSort(int[] arr) { • (1)boolean swapped = true; • (2)int j = 0; • (3) inttmp; • (4) while (swapped) { • (5) swapped = false; • (6) j++; • (7) for(inti = 0; i < arr.length - j; i++) { • (8)if(arr[i] > arr[i + 1]) { • (9)tmp= arr[i]; • (10)arr[i] = arr[i + 1]; • (11)arr[i+ 1] = tmp; • (12) swapped = true; • } //if • }//for • } //while • (13)}