40 likes | 157 Views
This guide provides an in-depth look into the Bubble Sort algorithm, a fundamental sorting technique. It explains the mechanism of the algorithm, which operates by repeatedly swapping adjacent elements if they are in the wrong order. The exercise involves drawing a flow graph, identifying independent paths, and writing test cases based on path testing methodology for the provided Java implementation. With practical insights and example code, this resource is designed for software developers and testers looking to enhance their understanding of sorting algorithms and testing strategies.
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)}