Skip to content

Commit b11033b

Browse files
authored
Merge pull request eugenp#1 from eugenp/master
merging eugenp/tutorials/master
2 parents 2a61d64 + eeb7d1c commit b11033b

1,719 files changed

Lines changed: 35290 additions & 20211 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void printStatus() {
148148
System.out.println("Game Draw");
149149
break;
150150
case IN_PROGRESS:
151-
System.out.println("Game In rogress");
151+
System.out.println("Game In Progress");
152152
break;
153153
}
154154
}

algorithms/src/test/java/algorithms/HillClimbingAlgorithmTest.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package algorithms;
2+
3+
import com.baeldung.algorithms.hillclimbing.HillClimbing;
4+
import com.baeldung.algorithms.hillclimbing.State;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.Stack;
11+
12+
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertNotNull;
14+
import static org.junit.Assert.assertTrue;
15+
16+
public class HillClimbingAlgorithmUnitTest {
17+
private Stack<String> initStack;
18+
private Stack<String> goalStack;
19+
20+
@Before
21+
public void initStacks() {
22+
String blockArr[] = { "B", "C", "D", "A" };
23+
String goalBlockArr[] = { "A", "B", "C", "D" };
24+
initStack = new Stack<>();
25+
for (String block : blockArr)
26+
initStack.push(block);
27+
goalStack = new Stack<>();
28+
for (String block : goalBlockArr)
29+
goalStack.push(block);
30+
}
31+
32+
@Test
33+
public void givenInitAndGoalState_whenGetPathWithHillClimbing_thenPathFound() {
34+
HillClimbing hillClimbing = new HillClimbing();
35+
36+
List<State> path;
37+
try {
38+
path = hillClimbing.getRouteWithHillClimbing(initStack, goalStack);
39+
assertNotNull(path);
40+
assertEquals(path.get(path.size() - 1)
41+
.getState()
42+
.get(0), goalStack);
43+
} catch (Exception e) {
44+
e.printStackTrace();
45+
}
46+
}
47+
48+
@Test
49+
public void givenCurrentState_whenFindNextState_thenBetterHeuristics() {
50+
HillClimbing hillClimbing = new HillClimbing();
51+
List<Stack<String>> initList = new ArrayList<>();
52+
initList.add(initStack);
53+
State currentState = new State(initList);
54+
currentState.setHeuristics(hillClimbing.getHeuristicsValue(initList, goalStack));
55+
State nextState = hillClimbing.findNextState(currentState, goalStack);
56+
assertTrue(nextState.getHeuristics() > currentState.getHeuristics());
57+
}
58+
}

algorithms/src/test/java/algorithms/StringSearchAlgorithmsTest.java

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package algorithms;
2+
3+
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
import com.baeldung.algorithms.string.search.StringSearchAlgorithms;
8+
9+
public class StringSearchAlgorithmsUnitTest {
10+
11+
12+
@Test
13+
public void testStringSearchAlgorithms(){
14+
String text = "This is some nice text.";
15+
String pattern = "some";
16+
17+
int realPosition = text.indexOf(pattern);
18+
Assert.assertTrue(realPosition == StringSearchAlgorithms.simpleTextSearch(pattern.toCharArray(), text.toCharArray()));
19+
Assert.assertTrue(realPosition == StringSearchAlgorithms.RabinKarpMethod(pattern.toCharArray(), text.toCharArray()));
20+
Assert.assertTrue(realPosition == StringSearchAlgorithms.KnuthMorrisPrattSearch(pattern.toCharArray(), text.toCharArray()));
21+
Assert.assertTrue(realPosition == StringSearchAlgorithms.BoyerMooreHorspoolSimpleSearch(pattern.toCharArray(), text.toCharArray()));
22+
Assert.assertTrue(realPosition == StringSearchAlgorithms.BoyerMooreHorspoolSearch(pattern.toCharArray(), text.toCharArray()));
23+
}
24+
25+
}

algorithms/src/test/java/algorithms/binarysearch/BinarySearchTest.java

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package algorithms.binarysearch;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
import com.baeldung.algorithms.binarysearch.BinarySearch;
9+
10+
public class BinarySearchUnitTest {
11+
12+
int[] sortedArray = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9 };
13+
int key = 6;
14+
int expectedIndexForSearchKey = 7;
15+
int low = 0;
16+
int high = sortedArray.length - 1;
17+
List<Integer> sortedList = Arrays.asList(0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9);
18+
19+
@Test
20+
public void givenASortedArrayOfIntegers_whenBinarySearchRunIterativelyForANumber_thenGetIndexOfTheNumber() {
21+
BinarySearch binSearch = new BinarySearch();
22+
Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchIteratively(sortedArray, key, low, high));
23+
}
24+
25+
@Test
26+
public void givenASortedArrayOfIntegers_whenBinarySearchRunRecursivelyForANumber_thenGetIndexOfTheNumber() {
27+
BinarySearch binSearch = new BinarySearch();
28+
Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchRecursively(sortedArray, key, low, high));
29+
}
30+
31+
@Test
32+
public void givenASortedArrayOfIntegers_whenBinarySearchRunUsingArraysClassStaticMethodForANumber_thenGetIndexOfTheNumber() {
33+
BinarySearch binSearch = new BinarySearch();
34+
Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaArrays(sortedArray, key));
35+
}
36+
37+
@Test
38+
public void givenASortedListOfIntegers_whenBinarySearchRunUsingCollectionsClassStaticMethodForANumber_thenGetIndexOfTheNumber() {
39+
BinarySearch binSearch = new BinarySearch();
40+
Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaCollections(sortedList, key));
41+
}
42+
43+
}

algorithms/src/test/java/algorithms/mcts/MCTSTest.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)