mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 15:02:46 +08:00
Add automatic linter (#4214)
This commit is contained in:
@ -160,7 +160,6 @@ public class BinarySearch2dArrayTest {
|
||||
int target = 5;
|
||||
|
||||
// Assert that an empty array is not valid input for the method.
|
||||
assertThrows(ArrayIndexOutOfBoundsException.class,
|
||||
() -> BinarySearch2dArray.BinarySearch(arr, target));
|
||||
assertThrows(ArrayIndexOutOfBoundsException.class, () -> BinarySearch2dArray.BinarySearch(arr, target));
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,7 @@ import org.junit.jupiter.api.Test;
|
||||
class BreadthFirstSearchTest {
|
||||
|
||||
private static final DepthFirstSearch.Node rootNode = new DepthFirstSearch.Node("A",
|
||||
List.of(
|
||||
new DepthFirstSearch.Node("B",
|
||||
List.of(new DepthFirstSearch.Node("D"),
|
||||
new DepthFirstSearch.Node("F",
|
||||
List.of(new DepthFirstSearch.Node("H"), new DepthFirstSearch.Node("I"))))),
|
||||
new DepthFirstSearch.Node("C", List.of(new DepthFirstSearch.Node("G"))),
|
||||
new DepthFirstSearch.Node("E")));
|
||||
List.of(new DepthFirstSearch.Node("B", List.of(new DepthFirstSearch.Node("D"), new DepthFirstSearch.Node("F", List.of(new DepthFirstSearch.Node("H"), new DepthFirstSearch.Node("I"))))), new DepthFirstSearch.Node("C", List.of(new DepthFirstSearch.Node("G"))), new DepthFirstSearch.Node("E")));
|
||||
|
||||
@Test
|
||||
void searchI() {
|
||||
|
@ -180,8 +180,7 @@ class QuickSelectTest {
|
||||
|
||||
@Test
|
||||
void quickSelectNullList() {
|
||||
NullPointerException exception
|
||||
= assertThrows(NullPointerException.class, () -> QuickSelect.select(null, 0));
|
||||
NullPointerException exception = assertThrows(NullPointerException.class, () -> QuickSelect.select(null, 0));
|
||||
String expectedMsg = "The list of elements must not be null.";
|
||||
assertEquals(expectedMsg, exception.getMessage());
|
||||
}
|
||||
@ -189,24 +188,21 @@ class QuickSelectTest {
|
||||
@Test
|
||||
void quickSelectEmptyList() {
|
||||
List<String> objects = Collections.emptyList();
|
||||
IllegalArgumentException exception
|
||||
= assertThrows(IllegalArgumentException.class, () -> QuickSelect.select(objects, 0));
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> QuickSelect.select(objects, 0));
|
||||
String expectedMsg = "The list of elements must not be empty.";
|
||||
assertEquals(expectedMsg, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void quickSelectIndexOutOfLeftBound() {
|
||||
IndexOutOfBoundsException exception = assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> QuickSelect.select(Collections.singletonList(1), -1));
|
||||
IndexOutOfBoundsException exception = assertThrows(IndexOutOfBoundsException.class, () -> QuickSelect.select(Collections.singletonList(1), -1));
|
||||
String expectedMsg = "The index must not be negative.";
|
||||
assertEquals(expectedMsg, exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void quickSelectIndexOutOfRightBound() {
|
||||
IndexOutOfBoundsException exception = assertThrows(IndexOutOfBoundsException.class,
|
||||
() -> QuickSelect.select(Collections.singletonList(1), 1));
|
||||
IndexOutOfBoundsException exception = assertThrows(IndexOutOfBoundsException.class, () -> QuickSelect.select(Collections.singletonList(1), 1));
|
||||
String expectedMsg = "The index must be less than the number of elements.";
|
||||
assertEquals(expectedMsg, exception.getMessage());
|
||||
}
|
||||
@ -221,9 +217,7 @@ class QuickSelectTest {
|
||||
}
|
||||
|
||||
private static List<Character> generateRandomCharacters(int n) {
|
||||
return RANDOM.ints(n, ASCII_A, ASCII_Z)
|
||||
.mapToObj(i -> (char) i)
|
||||
.collect(Collectors.toList());
|
||||
return RANDOM.ints(n, ASCII_A, ASCII_Z).mapToObj(i -> (char) i).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> List<T> getSortedCopyOfList(List<T> list) {
|
||||
|
@ -7,8 +7,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class TestSearchInARowAndColWiseSortedMatrix {
|
||||
@Test
|
||||
public void searchItem() {
|
||||
int[][] matrix = {{3, 4, 5, 6, 7}, {8, 9, 10, 11, 12}, {14, 15, 16, 17, 18},
|
||||
{23, 24, 25, 26, 27}, {30, 31, 32, 33, 34}};
|
||||
int[][] matrix = {{3, 4, 5, 6, 7}, {8, 9, 10, 11, 12}, {14, 15, 16, 17, 18}, {23, 24, 25, 26, 27}, {30, 31, 32, 33, 34}};
|
||||
|
||||
var test = new SearchInARowAndColWiseSortedMatrix();
|
||||
int[] res = test.search(matrix, 16);
|
||||
@ -18,8 +17,7 @@ public class TestSearchInARowAndColWiseSortedMatrix {
|
||||
|
||||
@Test
|
||||
public void notFound() {
|
||||
int[][] matrix = {{3, 4, 5, 6, 7}, {8, 9, 10, 11, 12}, {14, 15, 16, 17, 18},
|
||||
{23, 24, 25, 26, 27}, {30, 31, 32, 33, 34}};
|
||||
int[][] matrix = {{3, 4, 5, 6, 7}, {8, 9, 10, 11, 12}, {14, 15, 16, 17, 18}, {23, 24, 25, 26, 27}, {30, 31, 32, 33, 34}};
|
||||
|
||||
var test = new SearchInARowAndColWiseSortedMatrix();
|
||||
int[] res = test.search(matrix, 96);
|
||||
|
Reference in New Issue
Block a user