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:
@ -36,7 +36,6 @@ public class ConwayTest {
|
||||
|
||||
@Test
|
||||
public void testGenerateNextElementWith1A1Z3E1R1T3G1F1D2E1S1C() {
|
||||
assertEquals("111A111Z131E111R111T131G111F111D121E111S111C",
|
||||
Conway.generateNextElement("1A1Z3E1R1T3G1F1D2E1S1C"));
|
||||
assertEquals("111A111Z131E111R111T131G111F111D121E111S111C", Conway.generateNextElement("1A1Z3E1R1T3G1F1D2E1S1C"));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user