style: format code (#4212)

close #4204
This commit is contained in:
acbin
2023-06-09 18:52:05 +08:00
committed by GitHub
parent ad03086f54
commit 00282efd8b
521 changed files with 5233 additions and 7309 deletions

View File

@ -1,28 +1,28 @@
package com.thealgorithms.dynamicprogramming;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class EggDroppingTest {
@Test
void hasMultipleEggSingleFloor(){
assertEquals(1,EggDropping.minTrials(3,1));
void hasMultipleEggSingleFloor() {
assertEquals(1, EggDropping.minTrials(3, 1));
}
@Test
void hasSingleEggSingleFloor(){
assertEquals(1,EggDropping.minTrials(1,1));
void hasSingleEggSingleFloor() {
assertEquals(1, EggDropping.minTrials(1, 1));
}
@Test
void hasSingleEggMultipleFloor(){
assertEquals(3,EggDropping.minTrials(1,3));
void hasSingleEggMultipleFloor() {
assertEquals(3, EggDropping.minTrials(1, 3));
}
@Test
void hasMultipleEggMultipleFloor(){
assertEquals(7,EggDropping.minTrials(100,101));
void hasMultipleEggMultipleFloor() {
assertEquals(7, EggDropping.minTrials(100, 101));
}
}

View File

@ -1,34 +1,34 @@
package com.thealgorithms.dynamicprogramming;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class KnapsackMemoizationTest {
KnapsackMemoization knapsackMemoization = new KnapsackMemoization();
@Test
void Test1() {
int[] weight = { 1, 3, 4, 5 };
int[] value = { 1, 4, 5, 7 };
int[] weight = {1, 3, 4, 5};
int[] value = {1, 4, 5, 7};
int capacity = 10;
assertEquals(13, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
void Test2() {
int[] weight = { 95, 4, 60, 32, 23, 72, 80, 62, 65, 46 };
int[] value = { 55, 10, 47, 5, 4, 50, 8, 61, 85, 87 };
int[] weight = {95, 4, 60, 32, 23, 72, 80, 62, 65, 46};
int[] value = {55, 10, 47, 5, 4, 50, 8, 61, 85, 87};
int capacity = 269;
assertEquals(295, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
void Test3() {
int[] weight = { 10, 20, 30 };
int[] value = { 60, 100, 120 };
int[] weight = {10, 20, 30};
int[] value = {60, 100, 120};
int capacity = 50;
assertEquals(220, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
}

View File

@ -1,10 +1,10 @@
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class LevenshteinDistanceTests {
@ParameterizedTest
@ -13,5 +13,4 @@ public class LevenshteinDistanceTests {
int result = LevenshteinDistance.calculateLevenshteinDistance(str1, str2);
assertEquals(distance, result);
}
}

View File

@ -1,127 +1,101 @@
package com.thealgorithms.dynamicprogramming;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/**
* @author georgioct@csd.auth.gr
*/
public class OptimalJobSchedulingTest {
@Test
public void testOptimalJobScheduling1(){
public void testOptimalJobScheduling1() {
int numberProcesses = 5;
int numberMachines = 4;
int[][] Run = {
{5, 1, 3, 2},
{4, 2, 1, 3},
{1, 5, 2, 1},
{2, 3, 4, 2},
{1, 1, 3, 1}};
int[][] Run = {{5, 1, 3, 2}, {4, 2, 1, 3}, {1, 5, 2, 1}, {2, 3, 4, 2}, {1, 1, 3, 1}};
int[][] Transfer = {
{0, 1, 2, 4},
{1, 0, 2, 3},
{2, 2, 0, 1},
{4, 3, 1, 0}};
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();
int[][] costs = {{5, 1, 3, 2}, {6, 3, 4, 5}, {5, 8, 6, 6}, {7, 9, 10, 8}, {8, 9, 12, 9}};
int[][] costs = {
{5, 1, 3, 2},
{6, 3, 4, 5},
{5, 8, 6, 6},
{7, 9, 10, 8},
{8, 9, 12, 9}};
for (int i = 0; i < numberProcesses; i++) {
for (int i=0; i < numberProcesses; i++){
for (int j = 0; j < numberMachines; j++) {
for (int j=0; j < numberMachines; j++){
assertEquals(costs[i][j],opt.getCost(i,j));
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}
@Test
public void testOptimalJobScheduling2(){
public void testOptimalJobScheduling2() {
int numberProcesses = 3;
int numberMachines = 3;
int[][] Run = {
{5, 1, 3},
{4, 2, 1},
{1, 5, 2}};
int[][] Run = {{5, 1, 3}, {4, 2, 1}, {1, 5, 2}};
int[][] Transfer = {
{0, 1, 2},
{1, 0, 2},
{2, 2, 0}};
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();
int[][] costs = {
{5, 1, 3},
{6, 3, 4},
{5, 8, 6}};
int[][] costs = {{5, 1, 3}, {6, 3, 4}, {5, 8, 6}};
for (int i=0; i < numberProcesses; i++){
for (int i = 0; i < numberProcesses; i++) {
for (int j=0; j < numberMachines; j++){
for (int j = 0; j < numberMachines; j++) {
assertEquals(costs[i][j],opt.getCost(i,j));
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}
@Test
public void testOptimalJobScheduling3(){
public void testOptimalJobScheduling3() {
int numberProcesses = 6;
int numberMachines = 4;
int[][] Run = {
{5, 1, 3, 2},
{4, 2, 1, 1},
{1, 5, 2, 6},
{1, 1, 2, 3},
{2, 1, 4, 6},
{3, 2, 2, 3},
{5, 1, 3, 2},
{4, 2, 1, 1},
{1, 5, 2, 6},
{1, 1, 2, 3},
{2, 1, 4, 6},
{3, 2, 2, 3},
};
int[][] Transfer = {
{0, 1, 2, 1},
{1, 0, 2, 3},
{2, 2, 0, 2},
{1, 3, 2, 0},
{0, 1, 2, 1},
{1, 0, 2, 3},
{2, 2, 0, 2},
{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++){
for (int i = 0; i < numberProcesses; i++) {
for (int j=0; j < numberMachines; j++){
for (int j = 0; j < numberMachines; j++) {
assertEquals(costs[i][j],opt.getCost(i,j));
assertEquals(costs[i][j], opt.getCost(i, j));
}
}
}

View File

@ -1,24 +1,24 @@
package com.thealgorithms.dynamicprogramming;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class PartitionProblemTest {
@Test
public void testIfSumOfTheArrayIsOdd(){
assertFalse(PartitionProblem.partition(new int[]{1, 2, 2}));
public void testIfSumOfTheArrayIsOdd() {
assertFalse(PartitionProblem.partition(new int[] {1, 2, 2}));
}
@Test
public void testIfSizeOfTheArrayIsOne(){
assertFalse(PartitionProblem.partition(new int[]{2}));
public void testIfSizeOfTheArrayIsOne() {
assertFalse(PartitionProblem.partition(new int[] {2}));
}
@Test
public void testIfSumOfTheArrayIsEven1(){
assertTrue(PartitionProblem.partition(new int[]{1, 2, 3, 6}));
public void testIfSumOfTheArrayIsEven1() {
assertTrue(PartitionProblem.partition(new int[] {1, 2, 3, 6}));
}
@Test
public void testIfSumOfTheArrayIsEven2(){
assertFalse(PartitionProblem.partition(new int[]{1, 2, 3, 8}));
public void testIfSumOfTheArrayIsEven2() {
assertFalse(PartitionProblem.partition(new int[] {1, 2, 3, 8}));
}
}

View File

@ -1,30 +1,31 @@
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class SubsetCountTest {
public static SubsetCount obj = new SubsetCount();
@Test
void hasMultipleSubset(){
int[] arr = new int[]{1,2,3,3};
void hasMultipleSubset() {
int[] arr = new int[] {1, 2, 3, 3};
assertEquals(3, obj.getCount(arr, 6));
}
@Test
void singleElementSubset(){
int[] arr = new int[]{1,1,1,1};
void singleElementSubset() {
int[] arr = new int[] {1, 1, 1, 1};
assertEquals(4, obj.getCount(arr, 1));
}
@Test
void hasMultipleSubsetSO(){
int[] arr = new int[]{1,2,3,3};
void hasMultipleSubsetSO() {
int[] arr = new int[] {1, 2, 3, 3};
assertEquals(3, obj.getCountSO(arr, 6));
}
@Test
void singleSubsetSO(){
int[] arr = new int[]{1,1,1,1};
assertEquals(1,obj.getCountSO(arr, 4));
void singleSubsetSO() {
int[] arr = new int[] {1, 1, 1, 1};
assertEquals(1, obj.getCountSO(arr, 4));
}
}

View File

@ -1,24 +1,33 @@
package com.thealgorithms.dynamicprogramming;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class climbStairsTest {
@Test
void climbStairsTestForTwo(){assertEquals(2, ClimbingStairs.numberOfWays(2));}
void climbStairsTestForTwo() {
assertEquals(2, ClimbingStairs.numberOfWays(2));
}
@Test
void climbStairsTestForZero(){assertEquals(0, ClimbingStairs.numberOfWays(0));}
void climbStairsTestForZero() {
assertEquals(0, ClimbingStairs.numberOfWays(0));
}
@Test
void climbStairsTestForOne(){assertEquals(1, ClimbingStairs.numberOfWays(1));}
void climbStairsTestForOne() {
assertEquals(1, ClimbingStairs.numberOfWays(1));
}
@Test
void climbStairsTestForFive(){assertEquals(8, ClimbingStairs.numberOfWays(5));}
void climbStairsTestForFive() {
assertEquals(8, ClimbingStairs.numberOfWays(5));
}
@Test
void climbStairsTestForThree(){assertEquals(3, ClimbingStairs.numberOfWays(3));}
void climbStairsTestForThree() {
assertEquals(3, ClimbingStairs.numberOfWays(3));
}
}