BAEL-2797 fixes done for PR :

* changed imports removed from other branches
* cobertura plugin removed
* copied packages removed from origin
This commit is contained in:
anilkivilcim.eray 2019-04-08 23:02:03 +03:00
parent 131db49f2a
commit eae0cee48b
21 changed files with 13 additions and 410 deletions

View File

@ -1,11 +1,11 @@
package com.baeldung.algorithms;
import java.util.Scanner;
import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
import java.util.Scanner;
public class RunAlgorithm {
public static void main(String[] args) throws InstantiationException, IllegalAccessException {

View File

@ -1,9 +1,9 @@
package com.baeldung.algorithms;
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
import org.junit.Assert;
import org.junit.Test;
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
public class AntColonyOptimizationLongRunningUnitTest {

View File

@ -1,9 +1,9 @@
package com.baeldung.algorithms;
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
import org.junit.Assert;
import org.junit.Test;
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
public class BinaryGeneticAlgorithmLongRunningUnitTest {

View File

@ -1,9 +1,9 @@
package com.baeldung.algorithms;
import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
import org.junit.Assert;
import org.junit.Test;
import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
public class SimulatedAnnealingLongRunningUnitTest {

View File

@ -1,29 +0,0 @@
package com.baeldung.algorithms.combination;
import java.util.Arrays;
import java.util.Iterator;
import org.apache.commons.math3.util.CombinatoricsUtils;
public class ApacheCommonsCombinationGenerator {
private static final int N = 6;
private static final int R = 3;
/**
* Print all combinations of r elements from a set
* @param n - number of elements in set
* @param r - number of elements in selection
*/
public static void generate(int n, int r) {
Iterator<int[]> iterator = CombinatoricsUtils.combinationsIterator(n, r);
while (iterator.hasNext()) {
final int[] combination = iterator.next();
System.out.println(Arrays.toString(combination));
}
}
public static void main(String[] args) {
generate(N, R);
}
}

View File

@ -1,13 +0,0 @@
package com.baeldung.algorithms.combination;
import org.paukov.combinatorics3.Generator;
public class CombinatoricsLibCombinationGenerator {
public static void main(String[] args) {
Generator.combination(0, 1, 2, 3, 4, 5)
.simple(3)
.stream()
.forEach(System.out::println);
}
}

View File

@ -1,17 +0,0 @@
package com.baeldung.algorithms.combination;
import java.util.Arrays;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
public class GuavaCombinationsGenerator {
public static void main(String[] args) {
Set<Set<Integer>> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3);
System.out.println(combinations.size());
System.out.println(Arrays.toString(combinations.toArray()));
}
}

View File

@ -1,52 +0,0 @@
package com.baeldung.algorithms.combination;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class IterativeCombinationGenerator {
private static final int N = 5;
private static final int R = 2;
/**
* Generate all combinations of r elements from a set
* @param n the number of elements in input set
* @param r the number of elements in a combination
* @return the list containing all combinations
*/
public List<int[]> generate(int n, int r) {
List<int[]> combinations = new ArrayList<>();
int[] combination = new int[r];
// initialize with lowest lexicographic combination
for (int i = 0; i < r; i++) {
combination[i] = i;
}
while (combination[r - 1] < n) {
combinations.add(combination.clone());
// generate next combination in lexicographic order
int t = r - 1;
while (t != 0 && combination[t] == n - r + t) {
t--;
}
combination[t]++;
for (int i = t + 1; i < r; i++) {
combination[i] = combination[i - 1] + 1;
}
}
return combinations;
}
public static void main(String[] args) {
IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
List<int[]> combinations = generator.generate(N, R);
System.out.println(combinations.size());
for (int[] combination : combinations) {
System.out.println(Arrays.toString(combination));
}
}
}

View File

@ -1,53 +0,0 @@
package com.baeldung.algorithms.combination;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SelectionRecursiveCombinationGenerator {
private static final int N = 6;
private static final int R = 3;
/**
* Generate all combinations of r elements from a set
* @param n - number of elements in input set
* @param r - number of elements to be chosen
* @return the list containing all combinations
*/
public List<int[]> generate(int n, int r) {
List<int[]> combinations = new ArrayList<>();
helper(combinations, new int[r], 0, n - 1, 0);
return combinations;
}
/**
* Choose elements from set by recursing over elements selected
* @param combinations - List to store generated combinations
* @param data - current combination
* @param start - starting element of remaining set
* @param end - last element of remaining set
* @param index - number of elements chosen so far.
*/
private void helper(List<int[]> combinations, int data[], int start, int end, int index) {
if (index == data.length) {
int[] combination = data.clone();
combinations.add(combination);
} else {
int max = Math.min(end, end + 1 - data.length + index);
for (int i = start; i <= max; i++) {
data[index] = i;
helper(combinations, data, i + 1, end, index + 1);
}
}
}
public static void main(String[] args) {
SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
List<int[]> combinations = generator.generate(N, R);
for (int[] combination : combinations) {
System.out.println(Arrays.toString(combination));
}
System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
}
}

View File

@ -1,50 +0,0 @@
package com.baeldung.algorithms.combination;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SetRecursiveCombinationGenerator {
private static final int N = 5;
private static final int R = 2;
/**
* Generate all combinations of r elements from a set
* @param n - number of elements in set
* @param r - number of elements in selection
* @return the list containing all combinations
*/
public List<int[]> generate(int n, int r) {
List<int[]> combinations = new ArrayList<>();
helper(combinations, new int[r], 0, n-1, 0);
return combinations;
}
/**
* @param combinations - List to contain the generated combinations
* @param data - List of elements in the selection
* @param start - index of the starting element in the remaining set
* @param end - index of the last element in the set
* @param index - number of elements selected so far
*/
private void helper(List<int[]> combinations, int data[], int start, int end, int index) {
if (index == data.length) {
int[] combination = data.clone();
combinations.add(combination);
} else if (start <= end) {
data[index] = start;
helper(combinations, data, start + 1, end, index + 1);
helper(combinations, data, start + 1, end, index);
}
}
public static void main(String[] args) {
SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
List<int[]> combinations = generator.generate(N, R);
for (int[] combination : combinations) {
System.out.println(Arrays.toString(combination));
}
System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
}
}

View File

@ -1,63 +0,0 @@
package com.baeldung.algorithms.factorial;
import java.math.BigInteger;
import java.util.stream.LongStream;
import org.apache.commons.math3.util.CombinatoricsUtils;
import com.google.common.math.BigIntegerMath;
public class Factorial {
public long factorialUsingForLoop(int n) {
long fact = 1;
for (int i = 2; i <= n; i++) {
fact = fact * i;
}
return fact;
}
public long factorialUsingStreams(int n) {
return LongStream.rangeClosed(1, n)
.reduce(1, (long x, long y) -> x * y);
}
public long factorialUsingRecursion(int n) {
if (n <= 2) {
return n;
}
return n * factorialUsingRecursion(n - 1);
}
private Long[] factorials = new Long[20];
public long factorialUsingMemoize(int n) {
if (factorials[n] != null) {
return factorials[n];
}
if (n <= 2) {
return n;
}
long nthValue = n * factorialUsingMemoize(n - 1);
factorials[n] = nthValue;
return nthValue;
}
public BigInteger factorialHavingLargeResult(int n) {
BigInteger result = BigInteger.ONE;
for (int i = 2; i <= n; i++)
result = result.multiply(BigInteger.valueOf(i));
return result;
}
public long factorialUsingApacheCommons(int n) {
return CombinatoricsUtils.factorial(n);
}
public BigInteger factorialUsingGuava(int n) {
return BigIntegerMath.factorial(n);
}
}

View File

@ -2,9 +2,9 @@ package com.baeldung.algorithms.mcts.montecarlo;
import java.util.List;
import com.baeldung.algorithms.mcts.tictactoe.Board;
import com.baeldung.algorithms.mcts.tree.Node;
import com.baeldung.algorithms.mcts.tree.Tree;
import com.baeldung.algorithms.mcts.tictactoe.Board;
public class MonteCarloTreeSearch {

View File

@ -2,6 +2,7 @@ package com.baeldung.algorithms.mcts.montecarlo;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.baeldung.algorithms.mcts.tree.Node;

View File

@ -1,6 +1,7 @@
package com.baeldung.algorithms.mcts.tictactoe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Board {

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.baeldung.algorithms.binarysearch.BinarySearch;
public class BinarySearchUnitTest {

View File

@ -1,35 +0,0 @@
package com.baeldung.algorithms.combination;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.junit.Test;
public class CombinationUnitTest {
private static final int N = 5;
private static final int R = 3;
private static final int nCr = 10;
@Test
public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() {
SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
List<int[]> selection = generator.generate(N, R);
assertEquals(nCr, selection.size());
}
@Test
public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() {
SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
List<int[]> selection = generator.generate(N, R);
assertEquals(nCr, selection.size());
}
@Test
public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() {
IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
List<int[]> selection = generator.generate(N, R);
assertEquals(nCr, selection.size());
}
}

View File

@ -1,72 +0,0 @@
package com.baeldung.algorithms.factorial;
import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigInteger;
import org.junit.Before;
import org.junit.Test;
public class FactorialUnitTest {
Factorial factorial;
@Before
public void setup() {
factorial = new Factorial();
}
@Test
public void whenCalculatingFactorialUsingForLoop_thenCorrect() {
int n = 5;
assertThat(factorial.factorialUsingForLoop(n)).isEqualTo(120);
}
@Test
public void whenCalculatingFactorialUsingStreams_thenCorrect() {
int n = 5;
assertThat(factorial.factorialUsingStreams(n)).isEqualTo(120);
}
@Test
public void whenCalculatingFactorialUsingRecursion_thenCorrect() {
int n = 5;
assertThat(factorial.factorialUsingRecursion(n)).isEqualTo(120);
}
@Test
public void whenCalculatingFactorialUsingMemoize_thenCorrect() {
int n = 5;
assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(120);
n = 6;
assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(720);
}
@Test
public void whenCalculatingFactorialHavingLargeResult_thenCorrect() {
int n = 22;
assertThat(factorial.factorialHavingLargeResult(n)).isEqualTo(new BigInteger("1124000727777607680000"));
}
@Test
public void whenCalculatingFactorialUsingApacheCommons_thenCorrect() {
int n = 5;
assertThat(factorial.factorialUsingApacheCommons(n)).isEqualTo(120);
}
@Test
public void whenCalculatingFactorialUsingGuava_thenCorrect() {
int n = 22;
assertThat(factorial.factorialUsingGuava(n)).isEqualTo(new BigInteger("1124000727777607680000"));
}
}

View File

@ -4,6 +4,8 @@ import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import com.baeldung.algorithms.minimax.MiniMax;
import com.baeldung.algorithms.minimax.Tree;
public class MinimaxUnitTest {
private Tree gameTree;

View File

@ -1,6 +1,7 @@
package com.baeldung.algorithms.conversion;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.apache.commons.codec.DecoderException;
@ -8,6 +9,7 @@ import org.hamcrest.text.IsEqualIgnoringCase;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.algorithms.conversion.HexStringConverter;
public class ByteArrayConverterUnitTest {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -58,26 +58,6 @@
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<instrumentation>
<ignores>
<ignore>com/baeldung/math/dijkstra/*</ignore>
</ignores>
<excludes>
<exclude>com/baeldung/math/dijkstra/*</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
</plugins>
</reporting>
<properties>
<commons-math3.version>3.6.1</commons-math3.version>
<org.assertj.core.version>3.9.0</org.assertj.core.version>