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

@ -13,10 +13,8 @@ public class AllPathsFromSourceToTargetTest {
int[][] a = {{0, 1}, {0, 2}, {0, 3}, {2, 0}, {2, 1}, {1, 3}};
int source = 2;
int destination = 3;
List<List<Integer>> list2
= List.of(List.of(2, 0, 1, 3), List.of(2, 0, 3), List.of(2, 1, 3));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(
vertices, a, source, destination);
List<List<Integer>> list2 = List.of(List.of(2, 0, 1, 3), List.of(2, 0, 3), List.of(2, 1, 3));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(vertices, a, source, destination);
list2 = list1;
assertIterableEquals(list1, list2);
}
@ -27,10 +25,8 @@ public class AllPathsFromSourceToTargetTest {
int[][] a = {{0, 1}, {0, 2}, {0, 3}, {2, 0}, {2, 1}, {1, 3}, {1, 4}, {3, 4}, {2, 4}};
int source = 0;
int destination = 4;
List<List<Integer>> list2 = List.of(List.of(0, 1, 3, 4), List.of(0, 1, 4),
List.of(0, 2, 1, 3, 4), List.of(0, 2, 1, 4), List.of(0, 2, 4), List.of(0, 3, 4));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(
vertices, a, source, destination);
List<List<Integer>> list2 = List.of(List.of(0, 1, 3, 4), List.of(0, 1, 4), List.of(0, 2, 1, 3, 4), List.of(0, 2, 1, 4), List.of(0, 2, 4), List.of(0, 3, 4));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(vertices, a, source, destination);
list2 = list1;
assertIterableEquals(list1, list2);
}
@ -38,14 +34,11 @@ public class AllPathsFromSourceToTargetTest {
@Test
void testForThirdCase() {
int vertices = 6;
int[][] a = {{1, 0}, {2, 3}, {0, 4}, {1, 5}, {4, 3}, {0, 2}, {0, 3}, {1, 2}, {0, 5}, {3, 4},
{2, 5}, {2, 4}};
int[][] a = {{1, 0}, {2, 3}, {0, 4}, {1, 5}, {4, 3}, {0, 2}, {0, 3}, {1, 2}, {0, 5}, {3, 4}, {2, 5}, {2, 4}};
int source = 1;
int destination = 5;
List<List<Integer>> list2
= List.of(List.of(1, 0, 2, 5), List.of(1, 0, 5), List.of(1, 5), List.of(1, 2, 5));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(
vertices, a, source, destination);
List<List<Integer>> list2 = List.of(List.of(1, 0, 2, 5), List.of(1, 0, 5), List.of(1, 5), List.of(1, 2, 5));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(vertices, a, source, destination);
list2 = list1;
assertIterableEquals(list1, list2);
}
@ -57,8 +50,7 @@ public class AllPathsFromSourceToTargetTest {
int source = 0;
int destination = 2;
List<List<Integer>> list2 = List.of(List.of(0, 1, 2), List.of(0, 2));
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(
vertices, a, source, destination);
List<List<Integer>> list1 = AllPathsFromSourceToTarget.allPathsFromSourceToTarget(vertices, a, source, destination);
list2 = list1;
assertIterableEquals(list1, list2);
}

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));
}
}

View File

@ -33,8 +33,7 @@ class StrassenMatrixMultiplicationTest {
void StrassenMatrixMultiplicationTestNegetiveNumber4x4() {
int[][] A = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
int[][] B = {{1, -2, -3, 4}, {4, -3, -2, 1}, {5, -6, -7, 8}, {8, -7, -6, -5}};
int[][] expResult = {{56, -54, -52, 10}, {128, -126, -124, 42}, {200, -198, -196, 74},
{272, -270, -268, 106}};
int[][] expResult = {{56, -54, -52, 10}, {128, -126, -124, 42}, {200, -198, -196, 74}, {272, -270, -268, 106}};
int[][] actResult = SMM.multiply(A, B);
assertArrayEquals(expResult, actResult);
}

View File

@ -19,8 +19,7 @@ public class OptimalJobSchedulingTest {
int[][] Transfer = {{0, 1, 2, 4}, {1, 0, 2, 3}, {2, 2, 0, 1}, {4, 3, 1, 0}};
OptimalJobScheduling opt
= new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
opt.execute();
@ -45,8 +44,7 @@ public class OptimalJobSchedulingTest {
int[][] Transfer = {{0, 1, 2}, {1, 0, 2}, {2, 2, 0}};
OptimalJobScheduling opt
= new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
opt.execute();
@ -83,13 +81,11 @@ public class OptimalJobSchedulingTest {
{1, 3, 2, 0},
};
OptimalJobScheduling opt
= new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
OptimalJobScheduling opt = new OptimalJobScheduling(numberProcesses, numberMachines, Run, Transfer);
opt.execute();
int[][] costs = {{5, 1, 3, 2}, {6, 3, 4, 3}, {5, 8, 6, 9}, {6, 7, 8, 9}, {8, 8, 12, 13},
{11, 10, 12, 12}};
int[][] costs = {{5, 1, 3, 2}, {6, 3, 4, 3}, {5, 8, 6, 9}, {6, 7, 8, 9}, {8, 8, 12, 13}, {11, 10, 12, 12}};
for (int i = 0; i < numberProcesses; i++) {

View File

@ -7,9 +7,7 @@ import org.junit.jupiter.api.Test;
public class GrahamScanTest {
@Test
void testGrahamScan() {
GrahamScan.Point[] points = {new GrahamScan.Point(0, 3), new GrahamScan.Point(1, 1),
new GrahamScan.Point(2, 2), new GrahamScan.Point(4, 4), new GrahamScan.Point(0, 0),
new GrahamScan.Point(1, 2), new GrahamScan.Point(3, 1), new GrahamScan.Point(3, 3)};
GrahamScan.Point[] points = {new GrahamScan.Point(0, 3), new GrahamScan.Point(1, 1), new GrahamScan.Point(2, 2), new GrahamScan.Point(4, 4), new GrahamScan.Point(0, 0), new GrahamScan.Point(1, 2), new GrahamScan.Point(3, 1), new GrahamScan.Point(3, 3)};
String expectedResult = "[(0, 0), (3, 1), (4, 4), (0, 3)]";
GrahamScan graham = new GrahamScan(points);

View File

@ -13,8 +13,7 @@ public class ADTFractionTest {
@Test
void testConstructorWithDenominatorEqualToZero() {
Exception exception
= assertThrows(IllegalArgumentException.class, () -> new ADTFraction(1, 0));
Exception exception = assertThrows(IllegalArgumentException.class, () -> new ADTFraction(1, 0));
assertEquals("Denominator cannot be 0", exception.getMessage());
}

View File

@ -15,8 +15,7 @@ public class AbsoluteMinTest {
@Test
void testGetMinValueWithNoArguments() {
Exception exception
= assertThrows(IllegalArgumentException.class, () -> AbsoluteMin.getMinValue());
Exception exception = assertThrows(IllegalArgumentException.class, () -> AbsoluteMin.getMinValue());
assertEquals("Numbers array cannot be empty", exception.getMessage());
}
}

View File

@ -10,8 +10,6 @@ public class AbsoluteValueTest {
@Test
void testGetAbsValue() {
Stream.generate(() -> ThreadLocalRandom.current().nextInt())
.limit(1000)
.forEach(number -> assertEquals(Math.abs(number), AbsoluteValue.getAbsValue(number)));
Stream.generate(() -> ThreadLocalRandom.current().nextInt()).limit(1000).forEach(number -> assertEquals(Math.abs(number), AbsoluteValue.getAbsValue(number)));
}
}

View File

@ -66,53 +66,36 @@ class AreaTest {
@Test
void testAllIllegalInput() {
assertAll(
()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCube(0)),
assertAll(()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCube(0)),
()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaSphere(0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaRectangle(0, 10)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaRectangle(0, 10)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaRectangle(10, 0)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaRectangle(10, 0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaCylinder(0, 1)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCylinder(0, 1)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaCylinder(1, 0)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCylinder(1, 0)),
()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaSquare(0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaTriangleRectangle(0, 1)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaTriangleRectangle(0, 1)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaTriangleRectangle(1, 0)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaTriangleRectangle(1, 0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaParallelogram(0, 1)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaParallelogram(0, 1)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaParallelogram(1, 0)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaParallelogram(1, 0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(0, 1, 1)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(0, 1, 1)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(1, 0, 1)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(1, 0, 1)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(1, 1, 0)),
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaTrapezium(1, 1, 0)),
()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCircle(0)),
()
-> assertThrows(
IllegalArgumentException.class, () -> Area.surfaceAreaHemisphere(0)),
()
-> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCone(1, 0)),
() -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCone(0, 1)));
() -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaHemisphere(0)), () -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCone(1, 0)), () -> assertThrows(IllegalArgumentException.class, () -> Area.surfaceAreaCone(0, 1)));
}
}

View File

@ -20,9 +20,7 @@ public class AutomorphicNumberTest {
assertFalse(AutomorphicNumber.isAutomorphic2(n));
assertFalse(AutomorphicNumber.isAutomorphic3(String.valueOf(n)));
}
assertTrue(
AutomorphicNumber.isAutomorphic3("59918212890625")); // Special case for BigInteger
assertFalse(
AutomorphicNumber.isAutomorphic3("12345678912345")); // Special case for BigInteger
assertTrue(AutomorphicNumber.isAutomorphic3("59918212890625")); // Special case for BigInteger
assertFalse(AutomorphicNumber.isAutomorphic3("12345678912345")); // Special case for BigInteger
}
}

View File

@ -19,14 +19,12 @@ public class DistanceFormulaTest {
@Test
void euclideanTest3() {
Assertions.assertEquals(
DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100), 110.91911467371168);
Assertions.assertEquals(DistanceFormula.euclideanDistance(2.4, 9.1, 55.1, 100), 110.91911467371168);
}
@Test
void euclideanTest4() {
Assertions.assertEquals(
DistanceFormula.euclideanDistance(1000, 13, 20000, 84), 19022.067605809836);
Assertions.assertEquals(DistanceFormula.euclideanDistance(1000, 13, 20000, 84), 19022.067605809836);
}
@Test

View File

@ -47,8 +47,7 @@ public class GCDTest {
@Test
void testArrayGcd2() {
Assertions.assertEquals(
GCD.gcd(new int[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13}), 5);
Assertions.assertEquals(GCD.gcd(new int[] {2 * 3 * 5 * 7, 2 * 5 * 5 * 5, 2 * 5 * 11, 5 * 5 * 5 * 13}), 5);
}
@Test

View File

@ -13,8 +13,7 @@ class LiouvilleLambdaFunctionTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(IllegalArgumentException.class,
() -> { LiouvilleLambdaFunction.liouvilleLambda(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { LiouvilleLambdaFunction.liouvilleLambda(number); });
String actualMessage = exception.getMessage();
// then
@ -28,8 +27,7 @@ class LiouvilleLambdaFunctionTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(IllegalArgumentException.class,
() -> { LiouvilleLambdaFunction.liouvilleLambda(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { LiouvilleLambdaFunction.liouvilleLambda(number); });
String actualMessage = exception.getMessage();
// then

View File

@ -13,8 +13,7 @@ class MobiusFunctionTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(
IllegalArgumentException.class, () -> { MobiusFunction.mobius(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { MobiusFunction.mobius(number); });
String actualMessage = exception.getMessage();
// then
@ -28,8 +27,7 @@ class MobiusFunctionTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(
IllegalArgumentException.class, () -> { MobiusFunction.mobius(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { MobiusFunction.mobius(number); });
String actualMessage = exception.getMessage();
// then

View File

@ -40,8 +40,7 @@ class PollardRhoTest {
String expectedMessage = "GCD cannot be found.";
// when
Exception exception
= assertThrows(RuntimeException.class, () -> { PollardRho.pollardRho(number); });
Exception exception = assertThrows(RuntimeException.class, () -> { PollardRho.pollardRho(number); });
String actualMessage = exception.getMessage();
// then

View File

@ -12,107 +12,36 @@ class SquareFreeIntegerTest {
void testIsSquareFreeInteger() {
// given
List<Integer> listOfSquareFreeIntegers = List.of(1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17,
19, 21, 22, 23, 26, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 46, 47, 51, 53, 55,
57, 58, 59, 61, 62, 65, 66, 67, 69, 70, 71, 73, 74, 77, 78, 79, 82, 83, 85, 86, 87, 89,
91, 93, 94, 95, 97, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 118,
119, 122, 123, 127, 129, 130, 131, 133, 134, 137, 138, 139, 141, 142, 143, 145, 146,
149, 151, 154, 155, 157, 158, 159, 161, 163, 165, 166, 167, 170, 173, 174, 177, 178,
179, 181, 182, 183, 185, 186, 187, 190, 191, 193, 194, 195, 197, 199, 201, 202, 203,
205, 206, 209, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 226, 227, 229,
230, 231, 233, 235, 237, 238, 239, 241, 246, 247, 249, 251, 253, 254, 255, 257, 258,
259, 262, 263, 265, 266, 267, 269, 271, 273, 274, 277, 278, 281, 282, 283, 285, 286,
287, 290, 291, 293, 295, 298, 299, 301, 302, 303, 305, 307, 309, 310, 311, 313, 314,
317, 318, 319, 321, 322, 323, 326, 327, 329, 330, 331, 334, 335, 337, 339, 341, 345,
346, 347, 349, 353, 354, 355, 357, 358, 359, 362, 365, 366, 367, 370, 371, 373, 374,
377, 379, 381, 382, 383, 385, 386, 389, 390, 391, 393, 394, 395, 397, 398, 399, 401,
402, 403, 406, 407, 409, 410, 411, 413, 415, 417, 418, 419, 421, 422, 426, 427, 429,
430, 431, 433, 434, 435, 437, 438, 439, 442, 443, 445, 446, 447, 449, 451, 453, 454,
455, 457, 458, 461, 462, 463, 465, 466, 467, 469, 470, 471, 473, 474, 478, 479, 481,
482, 483, 485, 487, 489, 491, 493, 494, 497, 498, 499, 501, 502, 503, 505, 506, 509,
510, 511, 514, 515, 517, 518, 519, 521, 523, 526, 527, 530, 533, 534, 535, 537, 538,
541, 542, 543, 545, 546, 547, 551, 553, 554, 555, 557, 559, 561, 562, 563, 565, 566,
569, 570, 571, 573, 574, 577, 579, 581, 582, 583, 586, 587, 589, 590, 591, 593, 595,
597, 598, 599, 601, 602, 606, 607, 609, 610, 611, 613, 614, 615, 617, 618, 619, 622,
623, 626, 627, 629, 631, 633, 634, 635, 638, 641, 642, 643, 645, 646, 647, 649, 651,
653, 654, 655, 658, 659, 661, 662, 663, 665, 667, 669, 670, 671, 673, 674, 677, 678,
679, 681, 682, 683, 685, 687, 689, 690, 691, 694, 695, 697, 698, 699, 701, 703, 705,
706, 707, 709, 710, 713, 714, 715, 717, 718, 719, 721, 723, 727, 730, 731, 733, 734,
737, 739, 741, 742, 743, 745, 746, 749, 751, 753, 754, 755, 757, 758, 759, 761, 762,
763, 766, 767, 769, 770, 771, 773, 777, 778, 779, 781, 782, 785, 786, 787, 789, 790,
791, 793, 794, 795, 797, 798, 799, 802, 803, 805, 806, 807, 809, 811, 813, 814, 815,
817, 818, 821, 822, 823, 826, 827, 829, 830, 831, 834, 835, 838, 839, 842, 843, 849,
851, 853, 854, 857, 858, 859, 861, 862, 863, 865, 866, 869, 870, 871, 874, 877, 878,
879, 881, 883, 885, 886, 887, 889, 890, 893, 894, 895, 897, 898, 899, 901, 902, 903,
905, 906, 907, 910, 911, 913, 914, 915, 917, 919, 921, 922, 923, 926, 929, 930, 933,
934, 935, 937, 938, 939, 941, 942, 943, 946, 947, 949, 951, 953, 955, 957, 958, 959,
962, 965, 966, 967, 969, 970, 971, 973, 974, 977, 978, 979, 982, 983, 985, 986, 987,
989, 991, 993, 994, 995, 997, 998, 1001, 1002, 1003, 1005, 1006, 1007, 1009, 1010, 1011,
1013, 1015, 1018, 1019, 1021, 1022, 1023, 1027, 1030, 1031, 1033, 1034, 1037, 1038,
1039, 1041, 1042, 1043, 1045, 1046, 1047, 1049, 1051, 1054, 1055, 1057, 1059, 1061,
1063, 1065, 1066, 1067, 1069, 1070, 1073, 1074, 1077, 1079, 1081, 1082, 1085, 1086,
1087, 1090, 1091, 1093, 1094, 1095, 1097, 1099, 1101, 1102, 1103, 1105, 1106, 1109,
1110, 1111, 1113, 1114, 1115, 1117, 1118, 1119, 1121, 1122, 1123, 1126, 1129, 1130,
1131, 1133, 1135, 1137, 1138, 1139, 1141, 1142, 1145, 1146, 1147, 1149, 1151, 1153,
1154, 1155, 1157, 1158, 1159, 1162, 1163, 1165, 1166, 1167, 1169, 1171, 1173, 1174,
1177, 1178, 1181, 1182, 1185, 1186, 1187, 1189, 1190, 1191, 1193, 1194, 1195, 1198,
1199, 1201, 1202, 1203, 1205, 1207, 1209, 1211, 1213, 1214, 1217, 1218, 1219, 1221,
1222, 1223, 1226, 1227, 1229, 1230, 1231, 1234, 1235, 1237, 1238, 1239, 1241, 1243,
1245, 1246, 1247, 1249, 1253, 1254, 1255, 1257, 1258, 1259, 1261, 1262, 1263, 1265,
1266, 1267, 1270, 1271, 1273, 1277, 1279, 1281, 1282, 1283, 1285, 1286, 1289, 1290,
1291, 1293, 1294, 1295, 1297, 1298, 1299, 1301, 1302, 1303, 1306, 1307, 1309, 1310,
1311, 1313, 1315, 1317, 1318, 1319, 1321, 1322, 1326, 1327, 1329, 1330, 1333, 1334,
1335, 1337, 1338, 1339, 1342, 1343, 1345, 1346, 1347, 1349, 1351, 1353, 1354, 1355,
1357, 1358, 1361, 1362, 1363, 1365, 1366, 1367, 1370, 1371, 1373, 1374, 1378, 1379,
1381, 1382, 1383, 1385, 1387, 1389, 1390, 1391, 1393, 1394, 1397, 1398, 1399, 1401,
1402, 1403, 1405, 1406, 1407, 1409, 1410, 1411, 1414, 1415, 1417, 1418, 1419, 1423,
1426, 1427, 1429, 1430, 1433, 1434, 1435, 1437, 1438, 1439, 1441, 1442, 1443, 1446,
1447, 1451, 1453, 1454, 1455, 1457, 1459, 1461, 1462, 1463, 1465, 1466, 1469, 1471,
1473, 1474, 1477, 1478, 1479, 1481, 1482, 1483, 1486, 1487, 1489, 1490, 1491, 1493,
1495, 1497, 1498, 1499, 1501, 1502, 1505, 1506, 1507, 1509, 1510, 1511, 1513, 1514,
1515, 1517, 1518, 1522, 1523, 1526, 1527, 1529, 1531, 1533, 1534, 1535, 1537, 1538,
1541, 1542, 1543, 1545, 1546, 1547, 1549, 1551, 1553, 1554, 1555, 1558, 1559, 1561,
1562, 1563, 1565, 1567, 1569, 1570, 1571, 1574, 1577, 1578, 1579, 1581, 1582, 1583,
1585, 1586, 1589, 1590, 1591, 1594, 1595, 1597, 1598, 1599, 1601, 1603, 1605, 1606,
1607, 1609, 1610, 1613, 1614, 1615, 1618, 1619, 1621, 1622, 1623, 1626, 1627, 1630,
1631, 1633, 1634, 1635, 1637, 1639, 1641, 1642, 1643, 1645, 1646, 1649, 1651, 1653,
1654, 1655, 1657, 1658, 1659, 1661, 1662, 1663, 1667, 1669, 1670, 1671, 1673, 1677,
1678, 1679, 1685, 1686, 1687, 1689, 1691, 1693, 1695, 1697, 1698, 1699, 1702, 1703,
1705, 1706, 1707, 1709, 1711, 1713, 1714, 1717, 1718, 1721, 1722, 1723, 1726, 1727,
1729, 1730, 1731, 1733, 1735, 1738, 1739, 1741, 1742, 1743, 1745, 1747, 1749, 1751,
1753, 1754, 1757, 1758, 1759, 1761, 1762, 1763, 1765, 1766, 1767, 1769, 1770, 1771,
1774, 1777, 1778, 1779, 1781, 1783, 1785, 1786, 1787, 1789, 1790, 1793, 1794, 1795,
1797, 1798, 1799, 1801, 1802, 1803, 1806, 1807, 1810, 1811, 1814, 1817, 1819, 1821,
1822, 1823, 1826, 1829, 1830, 1831, 1833, 1834, 1835, 1837, 1838, 1839, 1841, 1842,
1843, 1846, 1847, 1851, 1853, 1855, 1857, 1858, 1861, 1865, 1866, 1867, 1869, 1870,
1871, 1873, 1874, 1877, 1878, 1879, 1882, 1883, 1885, 1886, 1887, 1889, 1891, 1893,
1894, 1895, 1897, 1898, 1901, 1902, 1903, 1905, 1906, 1907, 1909, 1910, 1913, 1914,
1915, 1918, 1919, 1921, 1923, 1927, 1929, 1930, 1931, 1933, 1934, 1937, 1938, 1939,
1941, 1942, 1943, 1945, 1946, 1947, 1949, 1951, 1954, 1955, 1957, 1958, 1959, 1961,
1963, 1965, 1966, 1967, 1969, 1970, 1973, 1974, 1977, 1978, 1979, 1981, 1982, 1983,
1985, 1986, 1987, 1990, 1991, 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2005,
2006, 2010, 2011, 2013, 2014, 2015, 2017, 2018, 2019, 2021, 2022, 2026, 2027, 2029,
2030, 2031, 2033, 2035, 2037, 2038, 2039, 2041, 2042, 2045, 2046, 2047, 2049, 2051,
2053, 2054, 2055, 2059, 2062, 2063, 2065, 2066, 2067, 2069, 2071, 2073, 2074, 2077,
2078, 2081, 2082, 2083, 2085, 2086, 2087, 2089, 2090, 2091, 2093, 2094, 2095, 2098,
2099, 2101, 2102, 2103, 2105, 2109, 2110, 2111, 2113, 2114, 2117, 2118, 2119, 2121,
2122, 2123, 2126, 2127, 2129, 2130, 2131, 2134, 2135, 2137, 2138, 2139, 2141, 2143,
2145, 2146, 2147, 2149, 2153, 2154, 2155, 2157, 2158, 2159, 2161, 2162, 2163, 2165,
2167, 2170, 2171, 2173, 2174, 2177, 2179, 2181, 2182, 2183, 2185, 2186, 2189, 2190,
2191, 2193, 2194, 2195, 2198, 2199, 2201, 2202, 2203, 2206, 2207, 2210, 2211, 2213,
2215, 2217, 2218, 2219, 2221, 2222, 2226, 2227, 2229, 2230, 2231, 2233, 2234, 2235,
2237, 2238, 2239, 2242, 2243, 2245, 2246, 2247, 2249, 2251, 2253, 2255, 2257, 2258,
2261, 2262, 2263, 2265, 2266, 2267, 2269, 2270, 2271, 2273, 2274, 2278, 2279, 2281,
2282, 2283, 2285, 2287, 2289, 2290, 2291, 2293, 2294, 2297, 2298, 2301, 2302, 2305,
2306, 2307, 2309, 2310, 2311, 2314, 2315, 2317, 2318, 2319, 2321, 2323, 2326, 2327,
2329, 2330, 2333, 2334, 2335, 2337, 2338, 2339, 2341, 2342, 2343, 2345, 2346, 2347,
2351, 2353, 2354, 2355, 2357, 2359, 2361, 2362, 2363, 2365, 2369, 2370, 2371, 2373,
2374, 2377, 2378, 2379, 2381, 2382, 2383, 2386, 2387, 2389, 2390, 2391, 2393, 2395,
2397, 2398, 2399, 2402, 2405, 2406, 2407, 2409, 2410, 2411, 2413, 2414, 2415, 2417,
2418, 2419, 2422, 2423, 2426, 2427, 2429, 2431, 2433, 2434, 2435, 2437, 2438, 2441,
2442, 2443, 2445, 2446, 2447, 2449, 2451, 2453, 2454, 2455, 2458, 2459, 2461, 2462,
2463, 2465, 2467, 2469, 2470, 2471, 2473, 2474, 2477, 2478, 2479, 2481, 2482, 2483,
2485, 2486, 2487, 2489, 2490, 2491, 2494, 2495, 2497, 2498);
List<Integer> listOfSquareFreeIntegers = List.of(1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 46, 47, 51, 53, 55, 57, 58, 59, 61, 62, 65, 66, 67, 69, 70, 71, 73, 74, 77, 78, 79, 82, 83, 85, 86, 87, 89, 91, 93, 94, 95, 97, 101,
102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 118, 119, 122, 123, 127, 129, 130, 131, 133, 134, 137, 138, 139, 141, 142, 143, 145, 146, 149, 151, 154, 155, 157, 158, 159, 161, 163, 165, 166, 167, 170, 173, 174, 177, 178, 179, 181, 182, 183, 185, 186, 187, 190, 191, 193, 194,
195, 197, 199, 201, 202, 203, 205, 206, 209, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 226, 227, 229, 230, 231, 233, 235, 237, 238, 239, 241, 246, 247, 249, 251, 253, 254, 255, 257, 258, 259, 262, 263, 265, 266, 267, 269, 271, 273, 274, 277, 278, 281, 282, 283, 285, 286,
287, 290, 291, 293, 295, 298, 299, 301, 302, 303, 305, 307, 309, 310, 311, 313, 314, 317, 318, 319, 321, 322, 323, 326, 327, 329, 330, 331, 334, 335, 337, 339, 341, 345, 346, 347, 349, 353, 354, 355, 357, 358, 359, 362, 365, 366, 367, 370, 371, 373, 374, 377, 379, 381, 382, 383, 385,
386, 389, 390, 391, 393, 394, 395, 397, 398, 399, 401, 402, 403, 406, 407, 409, 410, 411, 413, 415, 417, 418, 419, 421, 422, 426, 427, 429, 430, 431, 433, 434, 435, 437, 438, 439, 442, 443, 445, 446, 447, 449, 451, 453, 454, 455, 457, 458, 461, 462, 463, 465, 466, 467, 469, 470, 471,
473, 474, 478, 479, 481, 482, 483, 485, 487, 489, 491, 493, 494, 497, 498, 499, 501, 502, 503, 505, 506, 509, 510, 511, 514, 515, 517, 518, 519, 521, 523, 526, 527, 530, 533, 534, 535, 537, 538, 541, 542, 543, 545, 546, 547, 551, 553, 554, 555, 557, 559, 561, 562, 563, 565, 566, 569,
570, 571, 573, 574, 577, 579, 581, 582, 583, 586, 587, 589, 590, 591, 593, 595, 597, 598, 599, 601, 602, 606, 607, 609, 610, 611, 613, 614, 615, 617, 618, 619, 622, 623, 626, 627, 629, 631, 633, 634, 635, 638, 641, 642, 643, 645, 646, 647, 649, 651, 653, 654, 655, 658, 659, 661, 662,
663, 665, 667, 669, 670, 671, 673, 674, 677, 678, 679, 681, 682, 683, 685, 687, 689, 690, 691, 694, 695, 697, 698, 699, 701, 703, 705, 706, 707, 709, 710, 713, 714, 715, 717, 718, 719, 721, 723, 727, 730, 731, 733, 734, 737, 739, 741, 742, 743, 745, 746, 749, 751, 753, 754, 755, 757,
758, 759, 761, 762, 763, 766, 767, 769, 770, 771, 773, 777, 778, 779, 781, 782, 785, 786, 787, 789, 790, 791, 793, 794, 795, 797, 798, 799, 802, 803, 805, 806, 807, 809, 811, 813, 814, 815, 817, 818, 821, 822, 823, 826, 827, 829, 830, 831, 834, 835, 838, 839, 842, 843, 849, 851, 853,
854, 857, 858, 859, 861, 862, 863, 865, 866, 869, 870, 871, 874, 877, 878, 879, 881, 883, 885, 886, 887, 889, 890, 893, 894, 895, 897, 898, 899, 901, 902, 903, 905, 906, 907, 910, 911, 913, 914, 915, 917, 919, 921, 922, 923, 926, 929, 930, 933, 934, 935, 937, 938, 939, 941, 942, 943,
946, 947, 949, 951, 953, 955, 957, 958, 959, 962, 965, 966, 967, 969, 970, 971, 973, 974, 977, 978, 979, 982, 983, 985, 986, 987, 989, 991, 993, 994, 995, 997, 998, 1001, 1002, 1003, 1005, 1006, 1007, 1009, 1010, 1011, 1013, 1015, 1018, 1019, 1021, 1022, 1023, 1027, 1030, 1031, 1033,
1034, 1037, 1038, 1039, 1041, 1042, 1043, 1045, 1046, 1047, 1049, 1051, 1054, 1055, 1057, 1059, 1061, 1063, 1065, 1066, 1067, 1069, 1070, 1073, 1074, 1077, 1079, 1081, 1082, 1085, 1086, 1087, 1090, 1091, 1093, 1094, 1095, 1097, 1099, 1101, 1102, 1103, 1105, 1106, 1109, 1110, 1111, 1113,
1114, 1115, 1117, 1118, 1119, 1121, 1122, 1123, 1126, 1129, 1130, 1131, 1133, 1135, 1137, 1138, 1139, 1141, 1142, 1145, 1146, 1147, 1149, 1151, 1153, 1154, 1155, 1157, 1158, 1159, 1162, 1163, 1165, 1166, 1167, 1169, 1171, 1173, 1174, 1177, 1178, 1181, 1182, 1185, 1186, 1187, 1189, 1190,
1191, 1193, 1194, 1195, 1198, 1199, 1201, 1202, 1203, 1205, 1207, 1209, 1211, 1213, 1214, 1217, 1218, 1219, 1221, 1222, 1223, 1226, 1227, 1229, 1230, 1231, 1234, 1235, 1237, 1238, 1239, 1241, 1243, 1245, 1246, 1247, 1249, 1253, 1254, 1255, 1257, 1258, 1259, 1261, 1262, 1263, 1265, 1266,
1267, 1270, 1271, 1273, 1277, 1279, 1281, 1282, 1283, 1285, 1286, 1289, 1290, 1291, 1293, 1294, 1295, 1297, 1298, 1299, 1301, 1302, 1303, 1306, 1307, 1309, 1310, 1311, 1313, 1315, 1317, 1318, 1319, 1321, 1322, 1326, 1327, 1329, 1330, 1333, 1334, 1335, 1337, 1338, 1339, 1342, 1343, 1345,
1346, 1347, 1349, 1351, 1353, 1354, 1355, 1357, 1358, 1361, 1362, 1363, 1365, 1366, 1367, 1370, 1371, 1373, 1374, 1378, 1379, 1381, 1382, 1383, 1385, 1387, 1389, 1390, 1391, 1393, 1394, 1397, 1398, 1399, 1401, 1402, 1403, 1405, 1406, 1407, 1409, 1410, 1411, 1414, 1415, 1417, 1418, 1419,
1423, 1426, 1427, 1429, 1430, 1433, 1434, 1435, 1437, 1438, 1439, 1441, 1442, 1443, 1446, 1447, 1451, 1453, 1454, 1455, 1457, 1459, 1461, 1462, 1463, 1465, 1466, 1469, 1471, 1473, 1474, 1477, 1478, 1479, 1481, 1482, 1483, 1486, 1487, 1489, 1490, 1491, 1493, 1495, 1497, 1498, 1499, 1501,
1502, 1505, 1506, 1507, 1509, 1510, 1511, 1513, 1514, 1515, 1517, 1518, 1522, 1523, 1526, 1527, 1529, 1531, 1533, 1534, 1535, 1537, 1538, 1541, 1542, 1543, 1545, 1546, 1547, 1549, 1551, 1553, 1554, 1555, 1558, 1559, 1561, 1562, 1563, 1565, 1567, 1569, 1570, 1571, 1574, 1577, 1578, 1579,
1581, 1582, 1583, 1585, 1586, 1589, 1590, 1591, 1594, 1595, 1597, 1598, 1599, 1601, 1603, 1605, 1606, 1607, 1609, 1610, 1613, 1614, 1615, 1618, 1619, 1621, 1622, 1623, 1626, 1627, 1630, 1631, 1633, 1634, 1635, 1637, 1639, 1641, 1642, 1643, 1645, 1646, 1649, 1651, 1653, 1654, 1655, 1657,
1658, 1659, 1661, 1662, 1663, 1667, 1669, 1670, 1671, 1673, 1677, 1678, 1679, 1685, 1686, 1687, 1689, 1691, 1693, 1695, 1697, 1698, 1699, 1702, 1703, 1705, 1706, 1707, 1709, 1711, 1713, 1714, 1717, 1718, 1721, 1722, 1723, 1726, 1727, 1729, 1730, 1731, 1733, 1735, 1738, 1739, 1741, 1742,
1743, 1745, 1747, 1749, 1751, 1753, 1754, 1757, 1758, 1759, 1761, 1762, 1763, 1765, 1766, 1767, 1769, 1770, 1771, 1774, 1777, 1778, 1779, 1781, 1783, 1785, 1786, 1787, 1789, 1790, 1793, 1794, 1795, 1797, 1798, 1799, 1801, 1802, 1803, 1806, 1807, 1810, 1811, 1814, 1817, 1819, 1821, 1822,
1823, 1826, 1829, 1830, 1831, 1833, 1834, 1835, 1837, 1838, 1839, 1841, 1842, 1843, 1846, 1847, 1851, 1853, 1855, 1857, 1858, 1861, 1865, 1866, 1867, 1869, 1870, 1871, 1873, 1874, 1877, 1878, 1879, 1882, 1883, 1885, 1886, 1887, 1889, 1891, 1893, 1894, 1895, 1897, 1898, 1901, 1902, 1903,
1905, 1906, 1907, 1909, 1910, 1913, 1914, 1915, 1918, 1919, 1921, 1923, 1927, 1929, 1930, 1931, 1933, 1934, 1937, 1938, 1939, 1941, 1942, 1943, 1945, 1946, 1947, 1949, 1951, 1954, 1955, 1957, 1958, 1959, 1961, 1963, 1965, 1966, 1967, 1969, 1970, 1973, 1974, 1977, 1978, 1979, 1981, 1982,
1983, 1985, 1986, 1987, 1990, 1991, 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2005, 2006, 2010, 2011, 2013, 2014, 2015, 2017, 2018, 2019, 2021, 2022, 2026, 2027, 2029, 2030, 2031, 2033, 2035, 2037, 2038, 2039, 2041, 2042, 2045, 2046, 2047, 2049, 2051, 2053, 2054, 2055, 2059, 2062,
2063, 2065, 2066, 2067, 2069, 2071, 2073, 2074, 2077, 2078, 2081, 2082, 2083, 2085, 2086, 2087, 2089, 2090, 2091, 2093, 2094, 2095, 2098, 2099, 2101, 2102, 2103, 2105, 2109, 2110, 2111, 2113, 2114, 2117, 2118, 2119, 2121, 2122, 2123, 2126, 2127, 2129, 2130, 2131, 2134, 2135, 2137, 2138,
2139, 2141, 2143, 2145, 2146, 2147, 2149, 2153, 2154, 2155, 2157, 2158, 2159, 2161, 2162, 2163, 2165, 2167, 2170, 2171, 2173, 2174, 2177, 2179, 2181, 2182, 2183, 2185, 2186, 2189, 2190, 2191, 2193, 2194, 2195, 2198, 2199, 2201, 2202, 2203, 2206, 2207, 2210, 2211, 2213, 2215, 2217, 2218,
2219, 2221, 2222, 2226, 2227, 2229, 2230, 2231, 2233, 2234, 2235, 2237, 2238, 2239, 2242, 2243, 2245, 2246, 2247, 2249, 2251, 2253, 2255, 2257, 2258, 2261, 2262, 2263, 2265, 2266, 2267, 2269, 2270, 2271, 2273, 2274, 2278, 2279, 2281, 2282, 2283, 2285, 2287, 2289, 2290, 2291, 2293, 2294,
2297, 2298, 2301, 2302, 2305, 2306, 2307, 2309, 2310, 2311, 2314, 2315, 2317, 2318, 2319, 2321, 2323, 2326, 2327, 2329, 2330, 2333, 2334, 2335, 2337, 2338, 2339, 2341, 2342, 2343, 2345, 2346, 2347, 2351, 2353, 2354, 2355, 2357, 2359, 2361, 2362, 2363, 2365, 2369, 2370, 2371, 2373, 2374,
2377, 2378, 2379, 2381, 2382, 2383, 2386, 2387, 2389, 2390, 2391, 2393, 2395, 2397, 2398, 2399, 2402, 2405, 2406, 2407, 2409, 2410, 2411, 2413, 2414, 2415, 2417, 2418, 2419, 2422, 2423, 2426, 2427, 2429, 2431, 2433, 2434, 2435, 2437, 2438, 2441, 2442, 2443, 2445, 2446, 2447, 2449, 2451,
2453, 2454, 2455, 2458, 2459, 2461, 2462, 2463, 2465, 2467, 2469, 2470, 2471, 2473, 2474, 2477, 2478, 2479, 2481, 2482, 2483, 2485, 2486, 2487, 2489, 2490, 2491, 2494, 2495, 2497, 2498);
for (int i = 1; i <= 2500; i++) {
// when
@ -131,8 +60,7 @@ class SquareFreeIntegerTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(IllegalArgumentException.class,
() -> { SquareFreeInteger.isSquareFreeInteger(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { SquareFreeInteger.isSquareFreeInteger(number); });
String actualMessage = exception.getMessage();
// then
@ -146,8 +74,7 @@ class SquareFreeIntegerTest {
String expectedMessage = "Number must be greater than zero.";
// when
Exception exception = assertThrows(IllegalArgumentException.class,
() -> { SquareFreeInteger.isSquareFreeInteger(number); });
Exception exception = assertThrows(IllegalArgumentException.class, () -> { SquareFreeInteger.isSquareFreeInteger(number); });
String actualMessage = exception.getMessage();
// then

View File

@ -36,7 +36,6 @@ public class ConwayTest {
@Test
public void testGenerateNextElementWith1A1Z3E1R1T3G1F1D2E1S1C() {
assertEquals("111A111Z131E111R111T131G111F111D121E111S111C",
Conway.generateNextElement("1A1Z3E1R1T3G1F1D2E1S1C"));
assertEquals("111A111Z131E111R111T131G111F111D121E111S111C", Conway.generateNextElement("1A1Z3E1R1T3G1F1D2E1S1C"));
}
}

View File

@ -16,18 +16,14 @@ public class LowestBasePalindromeTest {
assertTrue(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>()));
assertTrue(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1))));
assertTrue(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 1))));
assertTrue(
LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 1))));
assertTrue(
LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 2, 1))));
assertTrue(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 1))));
assertTrue(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 2, 1))));
}
@Test
public void testIsPalindromicNegative() {
assertFalse(
LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2))));
assertFalse(
LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 1, 1))));
assertFalse(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2))));
assertFalse(LowestBasePalindrome.isPalindromic(new ArrayList<Integer>(Arrays.asList(1, 2, 1, 1))));
}
@Test
@ -47,14 +43,12 @@ public class LowestBasePalindromeTest {
@Test
public void testIsPalindromicInBaseThrowsExceptionForNegativeNumbers() {
assertThrows(
IllegalArgumentException.class, () -> LowestBasePalindrome.isPalindromicInBase(-1, 5));
assertThrows(IllegalArgumentException.class, () -> LowestBasePalindrome.isPalindromicInBase(-1, 5));
}
@Test
public void testIsPalindromicInBaseThrowsExceptionForWrongBases() {
assertThrows(
IllegalArgumentException.class, () -> LowestBasePalindrome.isPalindromicInBase(10, 1));
assertThrows(IllegalArgumentException.class, () -> LowestBasePalindrome.isPalindromicInBase(10, 1));
}
@Test

View File

@ -9,8 +9,7 @@ public class PasswordGenTest {
@Test
public void failGenerationWithSameMinMaxLengthTest() {
int length = 10;
assertThrows(IllegalArgumentException.class,
() -> { PasswordGen.generatePassword(length, length); });
assertThrows(IllegalArgumentException.class, () -> { PasswordGen.generatePassword(length, length); });
}
@Test
@ -23,8 +22,7 @@ public class PasswordGenTest {
public void failGenerationWithMinLengthSmallerThanMaxLengthTest() {
int minLength = 10;
int maxLength = 5;
assertThrows(IllegalArgumentException.class,
() -> { PasswordGen.generatePassword(minLength, maxLength); });
assertThrows(IllegalArgumentException.class, () -> { PasswordGen.generatePassword(minLength, maxLength); });
}
@Test

View File

@ -8,12 +8,10 @@ import org.junit.jupiter.api.Test;
public class TestPrintMatrixInSpiralOrder {
@Test
public void testOne() {
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 printClass = new PrintAMatrixInSpiralOrder();
List<Integer> res = printClass.print(matrix, matrix.length, matrix[0].length);
List<Integer> list = List.of(3, 4, 5, 6, 7, 12, 18, 27, 34, 33, 32, 31, 30, 23, 14, 8, 9,
10, 11, 17, 26, 25, 24, 15, 16);
List<Integer> list = List.of(3, 4, 5, 6, 7, 12, 18, 27, 34, 33, 32, 31, 30, 23, 14, 8, 9, 10, 11, 17, 26, 25, 24, 15, 16);
assertIterableEquals(res, list);
}

View File

@ -46,8 +46,7 @@ public class HammingDistanceTest {
@Test
public void checkForLongDataBits() {
String senderBits = "10010101101010000100110100",
receiverBits = "00110100001011001100110101";
String senderBits = "10010101101010000100110100", receiverBits = "00110100001011001100110101";
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
Assertions.assertThat(answer).isEqualTo(7);
}
@ -56,16 +55,14 @@ public class HammingDistanceTest {
public void mismatchDataBits() {
String senderBits = "100010", receiverBits = "00011";
Exception ex = org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class,
() -> { int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits); });
Exception ex = org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () -> { int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits); });
Assertions.assertThat(ex.getMessage()).contains("bits should be same");
}
@Test
public void checkForLongDataBitsSame() {
String senderBits = "10010101101010000100110100",
receiverBits = "10010101101010000100110100";
String senderBits = "10010101101010000100110100", receiverBits = "10010101101010000100110100";
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
Assertions.assertThat(answer).isEqualTo(0);
}

View File

@ -11,8 +11,7 @@ class RRSchedulingTest {
@Test
public void testingProcesses() {
List<ProcessDetails> processes = addProcessesForRR();
final RRScheduling rrScheduling
= new RRScheduling(processes, 4); // for sending to RR with quantum value 4
final RRScheduling rrScheduling = new RRScheduling(processes, 4); // for sending to RR with quantum value 4
rrScheduling.scheduleProcesses();

View File

@ -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));
}
}

View File

@ -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() {

View File

@ -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) {

View File

@ -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);

View File

@ -31,11 +31,9 @@ public class CombSortTest {
@Test
public void combSortStringArray() {
String[] inputArray
= {"4gp8", "aBJ2", "85cW", "Pmk9", "ewZO", "meuU", "RhNd", "5TKB", "eDd5", "zzyo"};
String[] inputArray = {"4gp8", "aBJ2", "85cW", "Pmk9", "ewZO", "meuU", "RhNd", "5TKB", "eDd5", "zzyo"};
String[] outputArray = combSort.sort(inputArray);
String[] expectedArray
= {"4gp8", "5TKB", "85cW", "Pmk9", "RhNd", "aBJ2", "eDd5", "ewZO", "meuU", "zzyo"};
String[] expectedArray = {"4gp8", "5TKB", "85cW", "Pmk9", "RhNd", "aBJ2", "eDd5", "ewZO", "meuU", "zzyo"};
assertArrayEquals(outputArray, expectedArray);
}
@ -49,8 +47,7 @@ public class CombSortTest {
@Test
public void combSortDoubleArray() {
Double[] inputArray = {0.8335545399, 0.9346214114, 0.3096396752, 0.6433840668, 0.3973191975,
0.6118850724, 0.0553975453, 0.1961108601, 0.6172800885, 0.1065247772};
Double[] inputArray = {0.8335545399, 0.9346214114, 0.3096396752, 0.6433840668, 0.3973191975, 0.6118850724, 0.0553975453, 0.1961108601, 0.6172800885, 0.1065247772};
Double[] outputArray = combSort.sort(inputArray);
Double[] expectedArray = {
0.0553975453,

View File

@ -34,8 +34,7 @@ public class IntrospectiveSortTest {
// valid test case
public void StrandSortNullTest() {
Integer[] expectedArray = null;
assertThrows(
NullPointerException.class, () -> { new IntrospectiveSort().sort(expectedArray); });
assertThrows(NullPointerException.class, () -> { new IntrospectiveSort().sort(expectedArray); });
}
@Test

View File

@ -13,8 +13,7 @@ public class MergeSortRecursiveTest {
@Test
void testMergeSortRecursiveCase1() {
MergeSortRecursive mergeSortRecursive
= new MergeSortRecursive(Arrays.asList(5, 12, 9, 3, 15, 88));
MergeSortRecursive mergeSortRecursive = new MergeSortRecursive(Arrays.asList(5, 12, 9, 3, 15, 88));
List<Integer> expected = Arrays.asList(3, 5, 9, 12, 15, 88);
List<Integer> sorted = mergeSortRecursive.mergeSort();
@ -24,8 +23,7 @@ public class MergeSortRecursiveTest {
@Test
void testMergeSortRecursiveCase2() {
MergeSortRecursive mergeSortRecursive
= new MergeSortRecursive(Arrays.asList(-3, 5, 3, 4, 3, 7, 40, -20, 30, 0));
MergeSortRecursive mergeSortRecursive = new MergeSortRecursive(Arrays.asList(-3, 5, 3, 4, 3, 7, 40, -20, 30, 0));
List<Integer> expected = Arrays.asList(-20, -3, 0, 3, 3, 4, 5, 7, 30, 40);
List<Integer> sorted = mergeSortRecursive.mergeSort();

View File

@ -71,11 +71,9 @@ public class SlowSortTest {
@Test
public void slowSortStringSymbolArray() {
String[] inputArray
= {"cbf", "auk", "ó", "(b", "a", ")", "au", "á", "cba", "auk", "(a", "bhy", "cba"};
String[] inputArray = {"cbf", "auk", "ó", "(b", "a", ")", "au", "á", "cba", "auk", "(a", "bhy", "cba"};
String[] outputArray = slowSort.sort(inputArray);
String[] expectedOutput
= {"(a", "(b", ")", "a", "au", "auk", "auk", "bhy", "cba", "cba", "cbf", "á", "ó"};
String[] expectedOutput = {"(a", "(b", ")", "a", "au", "auk", "auk", "bhy", "cba", "cba", "cbf", "á", "ó"};
assertArrayEquals(outputArray, expectedOutput);
}
}

View File

@ -12,8 +12,7 @@ class StrandSortTest {
// valid test case
public void StrandSortNonDuplicateTest() {
int[] expectedArray = {1, 2, 3, 4, 5};
LinkedList<Integer> actualList
= StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(3, 1, 2, 4, 5)));
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(3, 1, 2, 4, 5)));
int[] actualArray = new int[actualList.size()];
for (int i = 0; i < actualList.size(); i++) {
actualArray[i] = actualList.get(i);
@ -25,8 +24,7 @@ class StrandSortTest {
// valid test case
public void StrandSortDuplicateTest() {
int[] expectedArray = {2, 2, 2, 5, 7};
LinkedList<Integer> actualList
= StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(7, 2, 2, 2, 5)));
LinkedList<Integer> actualList = StrandSort.strandSort(new LinkedList<Integer>(Arrays.asList(7, 2, 2, 2, 5)));
int[] actualArray = new int[actualList.size()];
for (int i = 0; i < actualList.size(); i++) {
actualArray[i] = actualList.get(i);

View File

@ -53,8 +53,7 @@ class TopologicalSortTest {
graph.addEdge("6", "2");
graph.addEdge("7", "");
graph.addEdge("8", "");
Exception exception
= assertThrows(BackEdgeException.class, () -> TopologicalSort.sort(graph));
Exception exception = assertThrows(BackEdgeException.class, () -> TopologicalSort.sort(graph));
String expected = "This graph contains a cycle. No linear ordering is possible. "
+ "Back edge: 6 -> 2";
assertEquals(exception.getMessage(), expected);

View File

@ -30,11 +30,9 @@ public class TreeSortTest {
@Test
public void treeSortStringArray() {
String[] inputArray
= {"F6w9", "l1qz", "dIxH", "larj", "kRzy", "vnNH", "3ftM", "hc4n", "C5Qi", "btGF"};
String[] inputArray = {"F6w9", "l1qz", "dIxH", "larj", "kRzy", "vnNH", "3ftM", "hc4n", "C5Qi", "btGF"};
String[] outputArray = treeSort.sort(inputArray);
String[] expectedArray
= {"3ftM", "C5Qi", "F6w9", "btGF", "dIxH", "hc4n", "kRzy", "l1qz", "larj", "vnNH"};
String[] expectedArray = {"3ftM", "C5Qi", "F6w9", "btGF", "dIxH", "hc4n", "kRzy", "l1qz", "larj", "vnNH"};
assertArrayEquals(outputArray, expectedArray);
}
@ -48,11 +46,9 @@ public class TreeSortTest {
@Test
public void treeSortDoubleArray() {
Double[] inputArray = {0.8047485045, 0.4493112337, 0.8298433723, 0.2691406748, 0.2482782839,
0.5976243420, 0.6746235284, 0.0552623569, 0.3515624123, 0.0536747336};
Double[] inputArray = {0.8047485045, 0.4493112337, 0.8298433723, 0.2691406748, 0.2482782839, 0.5976243420, 0.6746235284, 0.0552623569, 0.3515624123, 0.0536747336};
Double[] outputArray = treeSort.sort(inputArray);
Double[] expectedArray = {0.0536747336, 0.0552623569, 0.2482782839, 0.2691406748,
0.3515624123, 0.4493112337, 0.5976243420, 0.6746235284, 0.8047485045, 0.8298433723};
Double[] expectedArray = {0.0536747336, 0.0552623569, 0.2482782839, 0.2691406748, 0.3515624123, 0.4493112337, 0.5976243420, 0.6746235284, 0.8047485045, 0.8298433723};
assertArrayEquals(outputArray, expectedArray);
}
}

View File

@ -18,8 +18,7 @@ public class HammingDistanceTest {
@Test
void testNotEqualStringLengths() {
Exception exception = assertThrows(
Exception.class, () -> HammingDistance.calculateHammingDistance("ab", "abc"));
Exception exception = assertThrows(Exception.class, () -> HammingDistance.calculateHammingDistance("ab", "abc"));
assertEquals("String lengths must be equal", exception.getMessage());
}
}

View File

@ -76,8 +76,7 @@ class HorspoolSearchTest {
@Test
void testFindFirstPatternNull() {
assertThrows(
NullPointerException.class, () -> HorspoolSearch.findFirst(null, "Hello World"));
assertThrows(NullPointerException.class, () -> HorspoolSearch.findFirst(null, "Hello World"));
}
@Test

View File

@ -39,9 +39,7 @@ public class LetterCombinationsOfPhoneNumberTest {
// "bdg", "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh",
// "cdi", "ceg", "ceh", "cei", "cfg", "cfh", "cfi"]
int[] numbers4 = {2, 3, 4};
List<String> output4 = Arrays.asList("adg", "adh", "adi", "aeg", "aeh", "aei", "afg", "afh",
"afi", "bdg", "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh",
"cdi", "ceg", "ceh", "cei", "cfg", "cfh", "cfi");
List<String> output4 = Arrays.asList("adg", "adh", "adi", "aeg", "aeh", "aei", "afg", "afh", "afi", "bdg", "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh", "cdi", "ceg", "ceh", "cei", "cfg", "cfh", "cfi");
assertTrue(ob.printWords(numbers4, numbers4.length, 0, "").equals(output4));
}
}

View File

@ -10,14 +10,12 @@ public class PalindromeTest {
String[] palindromes = {null, "", "aba", "123321", "kayak"};
for (String s : palindromes) {
Assertions.assertTrue(Palindrome.isPalindrome(s) && Palindrome.isPalindromeRecursion(s)
&& Palindrome.isPalindromeTwoPointer(s));
Assertions.assertTrue(Palindrome.isPalindrome(s) && Palindrome.isPalindromeRecursion(s) && Palindrome.isPalindromeTwoPointer(s));
}
String[] notPalindromes = {"abb", "abc", "abc123", "kayaks"};
for (String s : notPalindromes) {
Assertions.assertFalse(Palindrome.isPalindrome(s) || Palindrome.isPalindromeRecursion(s)
|| Palindrome.isPalindromeTwoPointer(s));
Assertions.assertFalse(Palindrome.isPalindrome(s) || Palindrome.isPalindromeRecursion(s) || Palindrome.isPalindromeTwoPointer(s));
}
}
}

View File

@ -9,14 +9,12 @@ public class PangramTest {
@Test
public void testPangram() {
assertTrue(Pangram.isPangram("The quick brown fox jumps over the lazy dog"));
assertFalse(
Pangram.isPangram("The quick brown fox jumps over the azy dog")); // L is missing
assertFalse(Pangram.isPangram("The quick brown fox jumps over the azy dog")); // L is missing
assertFalse(Pangram.isPangram("+-1234 This string is not alphabetical"));
assertFalse(Pangram.isPangram("\u0000/\\ Invalid characters are alright too"));
assertTrue(Pangram.isPangram2("The quick brown fox jumps over the lazy dog"));
assertFalse(
Pangram.isPangram2("The quick brown fox jumps over the azy dog")); // L is missing
assertFalse(Pangram.isPangram2("The quick brown fox jumps over the azy dog")); // L is missing
assertFalse(Pangram.isPangram2("+-1234 This string is not alphabetical"));
assertFalse(Pangram.isPangram2("\u0000/\\ Invalid characters are alright too"));
}