-
Notifications
You must be signed in to change notification settings - Fork 20.8k
Closed
Description
Describe the solution you'd like
Remove the assert statements from BubbleSort class and implement unit tests.
These are the assert statements to be removed and the same test cases can be used with the assertArrayEquals statement.
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] */
}
Metadata
Metadata
Assignees
Labels
No labels