Skip to content

Commit 0b0ce2b

Browse files
author
EAlexa
authored
slight improvements (williamfiset#152)
* remove unnesessary variable f is never used and can be deleted safely * remove unnecessary variable Variable "in" defined in the scope of the loop is never used and can be safely deleted * static use of Method/Class InterpolationSearch is declared static, no need to instantiate
1 parent 0a87306 commit 0b0ce2b

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

src/main/java/com/williamfiset/algorithms/ai/GeneticAlgorithm_knapsack_01.java

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static long run(int capacity, int[] weights, int[] values) {
6363
// Setup selection roulette
6464
for (int i = 1; i <= P; i++) {
6565

66-
Individual in = generation[i];
6766
double norm = fitness[i] / fitnessSum;
6867

6968
lo[i] = hi[i - 1] = lo[i - 1] + norm;

src/main/java/com/williamfiset/algorithms/graphtheory/AStar_GridHeuristic.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public static double astar(
9696

9797
double g = node.g + edge.cost;
9898
double h = heuristic(X, Y, edge.to, end);
99-
double f = g + h;
100-
99+
101100
if (g < G[edge.to] || !openSet.contains(edge.to)) {
102101

103102
G[edge.to] = g;

src/test/java/com/williamfiset/algorithms/search/InterpolationSearchTest.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,32 @@
55
import org.junit.Test;
66

77
public class InterpolationSearchTest {
8-
private static InterpolationSearch search;
9-
10-
public static void prepareTest() {
11-
search = new InterpolationSearch();
12-
}
13-
8+
149
@Test
1510
public void testCoverage1() {
1611
int[] arr = {0, 1, 2, 3, 4, 5};
17-
int index = search.interpolationSearch(arr, 2);
12+
int index = InterpolationSearch.interpolationSearch(arr, 2);
1813
assertTrue(index == 2);
1914
}
2015

2116
@Test
2217
public void testCoverage2() {
2318
int[] arr = {0, 1, 2, 3, 4, 5};
24-
int index = search.interpolationSearch(arr, 5);
19+
int index = InterpolationSearch.interpolationSearch(arr, 5);
2520
assertTrue(index == 5);
2621
}
2722

2823
@Test
2924
public void testCoverage3() {
3025
int[] arr = {0, 1, 2, 3, 4, 5};
31-
int index = search.interpolationSearch(arr, -1);
26+
int index = InterpolationSearch.interpolationSearch(arr, -1);
3227
assertTrue(index == -1);
3328
}
3429

3530
@Test
3631
public void testCoverage4() {
3732
int[] arr = {0, 1, 2, 3, 4, 5};
38-
int index = search.interpolationSearch(arr, 8);
33+
int index = InterpolationSearch.interpolationSearch(arr, 8);
3934
assertTrue(index == -1);
4035
}
4136
}

0 commit comments

Comments
 (0)