Add automatic linter (#4214)

This commit is contained in:
acbin
2023-06-09 20:05:14 +08:00
committed by GitHub
parent 00282efd8b
commit 415a04ea7f
188 changed files with 661 additions and 1133 deletions

View File

@ -104,8 +104,7 @@ class CircularBufferTest {
private void shutDownExecutorSafely(ExecutorService executorService) {
try {
if (!executorService.awaitTermination(1_000, TimeUnit.MILLISECONDS))
executorService.shutdownNow();
if (!executorService.awaitTermination(1_000, TimeUnit.MILLISECONDS)) executorService.shutdownNow();
} catch (InterruptedException e) {
executorService.shutdownNow();
}

View File

@ -73,8 +73,7 @@ class SkipListTest {
Arrays.stream(values).forEach(skipList::add);
print(skipList);
String[] actualOrder
= IntStream.range(0, values.length).mapToObj(skipList::get).toArray(String[] ::new);
String[] actualOrder = IntStream.range(0, values.length).mapToObj(skipList::get).toArray(String[] ::new);
assertArrayEquals(new String[] {"a", "b", "c", "d"}, actualOrder);
}

View File

@ -29,8 +29,7 @@ public class CheckBinaryTreeIsValidBSTTest {
*/
@Test
public void testBinaryTreeIsBST() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 20});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 20});
assertTrue(CheckBinaryTreeIsValidBST.isBST(root));
}
@ -43,8 +42,7 @@ public class CheckBinaryTreeIsValidBSTTest {
*/
@Test
public void testBinaryTreeWithDuplicatedNodesIsNotBST() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 13});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 13});
assertFalse(CheckBinaryTreeIsValidBST.isBST(root));
}
@ -57,8 +55,7 @@ public class CheckBinaryTreeIsValidBSTTest {
*/
@Test
public void testBinaryTreeIsNotBST() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 12});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {9, 7, 13, 3, 8, 10, 12});
assertFalse(CheckBinaryTreeIsValidBST.isBST(root));
}
}

View File

@ -12,8 +12,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
public void testOnNullArraysShouldReturnNullTree() {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(null, null);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(null, null);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(null, null);
// then
Assertions.assertNull(root);
@ -28,8 +27,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(preorder, inorder);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
// then
Assertions.assertNull(root);
@ -44,8 +42,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(preorder, inorder);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
// then
checkTree(preorder, inorder, root);
@ -60,8 +57,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(preorder, inorder);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
// then
checkTree(preorder, inorder, root);
@ -76,8 +72,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(preorder, inorder);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
// then
checkTree(preorder, inorder, root);
@ -92,8 +87,7 @@ public class CreateBinaryTreeFromInorderPreorderTest {
// when
BinaryTree.Node root = CreateBinaryTreeFromInorderPreorder.createTree(preorder, inorder);
BinaryTree.Node rootOpt
= CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
BinaryTree.Node rootOpt = CreateBinaryTreeFromInorderPreorder.createTreeOptimized(preorder, inorder);
// then
checkTree(preorder, inorder, root);

View File

@ -43,8 +43,7 @@ public class InorderTraversalTest {
*/
@Test
public void testRecursiveInorderNonBalanced() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
List<Integer> expected = List.of(5, 6, 7, 8);
assertEquals(expected, InorderTraversal.recursiveInorder(root));

View File

@ -31,8 +31,7 @@ public class LevelOrderTraversalTest {
@Test
public void testLevelOrderTraversalCompleteTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7});
assertEquals(List.of(List.of(1), List.of(2, 3), List.of(4, 5, 6, 7)),
LevelOrderTraversal.traverse(root));
assertEquals(List.of(List.of(1), List.of(2, 3), List.of(4, 5, 6, 7)), LevelOrderTraversal.traverse(root));
}
/*
@ -46,9 +45,7 @@ public class LevelOrderTraversalTest {
*/
@Test
public void testLevelOrderTraversalDifferentHeight() {
final BinaryTree.Node root = TreeTestUtils.createTree(
new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(List.of(1), List.of(2, 3), List.of(4, 5, 6, 7), List.of(8, 9)),
LevelOrderTraversal.traverse(root));
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(List.of(1), List.of(2, 3), List.of(4, 5, 6, 7), List.of(8, 9)), LevelOrderTraversal.traverse(root));
}
}

View File

@ -45,8 +45,7 @@ public class PostOrderTraversalTest {
*/
@Test
public void testPostOrderNonBalanced() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
List<Integer> expected = List.of(8, 7, 6, 5);
assertEquals(expected, PostOrderTraversal.recursivePostOrder(root));

View File

@ -43,8 +43,7 @@ public class PreOrderTraversalTest {
*/
@Test
public void testRecursivePreOrderNonBalanced() {
final BinaryTree.Node root
= TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {5, null, 6, null, 7, null, 8});
List<Integer> expected = List.of(5, 6, 7, 8);
assertEquals(expected, PreOrderTraversal.recursivePreOrder(root));

View File

@ -45,9 +45,7 @@ public class VerticalOrderTraversalTest {
*/
@Test
public void testVerticalTraversalDifferentHeight() {
final BinaryTree.Node root = TreeTestUtils.createTree(
new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(
List.of(4, 2, 8, 1, 5, 6, 3, 9, 7), VerticalOrderTraversal.verticalTraversal(root));
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(4, 2, 8, 1, 5, 6, 3, 9, 7), VerticalOrderTraversal.verticalTraversal(root));
}
}

View File

@ -31,8 +31,7 @@ public class ZigzagTraversalTest {
@Test
public void testZigzagTraversalCompleteTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7});
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7)),
ZigzagTraversal.traverse(root));
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7)), ZigzagTraversal.traverse(root));
}
/*
@ -46,9 +45,7 @@ public class ZigzagTraversalTest {
*/
@Test
public void testZigzagTraversalDifferentHeight() {
final BinaryTree.Node root = TreeTestUtils.createTree(
new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7), List.of(9, 8)),
ZigzagTraversal.traverse(root));
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7), List.of(9, 8)), ZigzagTraversal.traverse(root));
}
}