style: enable ArrayTypeStyle
in checkstyle (#5145)
This commit is contained in:
parent
414835db11
commit
bfb27eeb59
@ -181,7 +181,7 @@
|
|||||||
|
|
||||||
<!-- Miscellaneous other checks. -->
|
<!-- Miscellaneous other checks. -->
|
||||||
<!-- See https://checkstyle.org/checks/misc/index.html -->
|
<!-- See https://checkstyle.org/checks/misc/index.html -->
|
||||||
<!-- TODO <module name="ArrayTypeStyle"/> -->
|
<module name="ArrayTypeStyle"/>
|
||||||
<!-- TODO <module name="FinalParameters"/> -->
|
<!-- TODO <module name="FinalParameters"/> -->
|
||||||
<!-- TODO <module name="TodoComment"/> -->
|
<!-- TODO <module name="TodoComment"/> -->
|
||||||
<module name="UpperEll"/>
|
<module name="UpperEll"/>
|
||||||
|
@ -8,7 +8,7 @@ package com.thealgorithms.ciphers;
|
|||||||
public class DES {
|
public class DES {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String subKeys[];
|
private String[] subKeys;
|
||||||
|
|
||||||
private void sanitize(String key) {
|
private void sanitize(String key) {
|
||||||
int length = key.length();
|
int length = key.length();
|
||||||
@ -78,7 +78,7 @@ public class DES {
|
|||||||
for (i = 0; i < 56; i++) {
|
for (i = 0; i < 56; i++) {
|
||||||
permutedKey.append(originalKey.charAt(PC1[i] - 1));
|
permutedKey.append(originalKey.charAt(PC1[i] - 1));
|
||||||
}
|
}
|
||||||
String subKeys[] = new String[16];
|
String[] subKeys = new String[16];
|
||||||
String initialPermutedKey = permutedKey.toString();
|
String initialPermutedKey = permutedKey.toString();
|
||||||
String C0 = initialPermutedKey.substring(0, 28), D0 = initialPermutedKey.substring(28);
|
String C0 = initialPermutedKey.substring(0, 28), D0 = initialPermutedKey.substring(28);
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ public class DES {
|
|||||||
return permutedString.toString();
|
return permutedString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String encryptBlock(String message, String keys[]) {
|
private String encryptBlock(String message, String[] keys) {
|
||||||
StringBuilder permutedMessage = new StringBuilder();
|
StringBuilder permutedMessage = new StringBuilder();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 64; i++) {
|
for (i = 0; i < 64; i++) {
|
||||||
@ -184,8 +184,8 @@ public class DES {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// To decode, we follow the same process as encoding, but with reversed keys
|
// To decode, we follow the same process as encoding, but with reversed keys
|
||||||
private String decryptBlock(String message, String keys[]) {
|
private String decryptBlock(String message, String[] keys) {
|
||||||
String reversedKeys[] = new String[keys.length];
|
String[] reversedKeys = new String[keys.length];
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
reversedKeys[i] = keys[keys.length - i - 1];
|
reversedKeys[i] = keys[keys.length - i - 1];
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ public class DES {
|
|||||||
for (i = 0; i < l; i += 64) {
|
for (i = 0; i < l; i += 64) {
|
||||||
String block = message.substring(i, i + 64);
|
String block = message.substring(i, i + 64);
|
||||||
String result = decryptBlock(block.toString(), subKeys);
|
String result = decryptBlock(block.toString(), subKeys);
|
||||||
byte res[] = new byte[8];
|
byte[] res = new byte[8];
|
||||||
for (j = 0; j < 64; j += 8) {
|
for (j = 0; j < 64; j += 8) {
|
||||||
res[j / 8] = (byte) Integer.parseInt(result.substring(j, j + 8), 2);
|
res[j / 8] = (byte) Integer.parseInt(result.substring(j, j + 8), 2);
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ class NonRepeatingNumberFinderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNonRepeatingNumberFinder() {
|
void testNonRepeatingNumberFinder() {
|
||||||
int arr[] = {1, 2, 1, 2, 6};
|
int[] arr = {1, 2, 1, 2, 6};
|
||||||
assertEquals(6, NonRepeatingNumberFinder.findNonRepeatingNumber(arr));
|
assertEquals(6, NonRepeatingNumberFinder.findNonRepeatingNumber(arr));
|
||||||
int arr1[] = {1, 2, 1, 2};
|
int[] arr1 = {1, 2, 1, 2};
|
||||||
assertEquals(0, NonRepeatingNumberFinder.findNonRepeatingNumber(arr1));
|
assertEquals(0, NonRepeatingNumberFinder.findNonRepeatingNumber(arr1));
|
||||||
int arr2[] = {12};
|
int[] arr2 = {12};
|
||||||
assertEquals(12, NonRepeatingNumberFinder.findNonRepeatingNumber(arr2));
|
assertEquals(12, NonRepeatingNumberFinder.findNonRepeatingNumber(arr2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ import org.junit.jupiter.api.Test;
|
|||||||
public class ActivitySelectionTest {
|
public class ActivitySelectionTest {
|
||||||
@Test
|
@Test
|
||||||
public void testActivitySelection() {
|
public void testActivitySelection() {
|
||||||
int start[] = {1, 3, 0, 5, 8, 5};
|
int[] start = {1, 3, 0, 5, 8, 5};
|
||||||
int end[] = {2, 4, 6, 7, 9, 9};
|
int[] end = {2, 4, 6, 7, 9, 9};
|
||||||
|
|
||||||
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
||||||
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0, 1, 3, 4));
|
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0, 1, 3, 4));
|
||||||
@ -20,8 +20,8 @@ public class ActivitySelectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleActivity() {
|
public void testSingleActivity() {
|
||||||
int start[] = {1};
|
int[] start = {1};
|
||||||
int end[] = {2};
|
int[] end = {2};
|
||||||
|
|
||||||
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
||||||
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0));
|
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0));
|
||||||
@ -31,8 +31,8 @@ public class ActivitySelectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoOverlap() {
|
public void testNoOverlap() {
|
||||||
int start[] = {1, 2, 3};
|
int[] start = {1, 2, 3};
|
||||||
int end[] = {2, 3, 4};
|
int[] end = {2, 3, 4};
|
||||||
|
|
||||||
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
|
||||||
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0, 1, 2));
|
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0, 1, 2));
|
||||||
|
@ -8,24 +8,24 @@ public class FractionalKnapsackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFractionalKnapsackWithExampleCase() {
|
public void testFractionalKnapsackWithExampleCase() {
|
||||||
int weight[] = {10, 20, 30};
|
int[] weight = {10, 20, 30};
|
||||||
int value[] = {60, 100, 120};
|
int[] value = {60, 100, 120};
|
||||||
int capacity = 50;
|
int capacity = 50;
|
||||||
assertEquals(240, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
assertEquals(240, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFractionalKnapsackWithZeroCapacity() {
|
public void testFractionalKnapsackWithZeroCapacity() {
|
||||||
int weight[] = {10, 20, 30};
|
int[] weight = {10, 20, 30};
|
||||||
int value[] = {60, 100, 120};
|
int[] value = {60, 100, 120};
|
||||||
int capacity = 0;
|
int capacity = 0;
|
||||||
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFractionalKnapsackWithEmptyItems() {
|
public void testFractionalKnapsackWithEmptyItems() {
|
||||||
int weight[] = {};
|
int[] weight = {};
|
||||||
int value[] = {};
|
int[] value = {};
|
||||||
int capacity = 50;
|
int capacity = 50;
|
||||||
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user