mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 09:06:51 +08:00
Add BubbleSort unit tests (#3275)
This commit is contained in:

committed by
GitHub

parent
276bbe2530
commit
a2dd154ad6
@ -32,28 +32,4 @@ class BubbleSort implements SortAlgorithm {
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Driver Code
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
|
||||
BubbleSort bubbleSort = new BubbleSort();
|
||||
bubbleSort.sort(integers);
|
||||
|
||||
for (int i = 0; i < integers.length - 1; ++i) {
|
||||
assert integers[i] <= integers[i + 1];
|
||||
}
|
||||
print(integers);
|
||||
/* output: [1, 4, 6, 9, 12, 23, 54, 78, 231] */
|
||||
|
||||
String[] strings = {"c", "a", "e", "b", "d"};
|
||||
bubbleSort.sort(strings);
|
||||
for (int i = 0; i < strings.length - 1; i++) {
|
||||
assert strings[i].compareTo(strings[i + 1]) <= 0;
|
||||
}
|
||||
print(bubbleSort.sort(strings));
|
||||
/* output: [a, b, c, d, e] */
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user