mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 16:27:33 +08:00
style: include OCP_OVERLY_CONCRETE_PARAMETER
(#5833)
This commit is contained in:
@ -87,9 +87,6 @@
|
|||||||
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
|
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
|
||||||
</Match>
|
</Match>
|
||||||
<!-- fb-contrib -->
|
<!-- fb-contrib -->
|
||||||
<Match>
|
|
||||||
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
|
|
||||||
</Match>
|
|
||||||
<Match>
|
<Match>
|
||||||
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
|
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
|
||||||
</Match>
|
</Match>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.backtracking;
|
package com.thealgorithms.backtracking;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +96,7 @@ public final class CrosswordSolver {
|
|||||||
* @param words The list of words to be placed.
|
* @param words The list of words to be placed.
|
||||||
* @return true if the crossword is solved, false otherwise.
|
* @return true if the crossword is solved, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean solveCrossword(char[][] puzzle, List<String> words) {
|
public static boolean solveCrossword(char[][] puzzle, Collection<String> words) {
|
||||||
// Create a mutable copy of the words list
|
// Create a mutable copy of the words list
|
||||||
List<String> remainingWords = new ArrayList<>(words);
|
List<String> remainingWords = new ArrayList<>(words);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public final class AStar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the graph with edges defined in the input data
|
// Initializes the graph with edges defined in the input data
|
||||||
static void initializeGraph(Graph graph, ArrayList<Integer> data) {
|
static void initializeGraph(Graph graph, List<Integer> data) {
|
||||||
for (int i = 0; i < data.size(); i += 4) {
|
for (int i = 0; i < data.size(); i += 4) {
|
||||||
graph.addEdge(new Edge(data.get(i), data.get(i + 1), data.get(i + 2)));
|
graph.addEdge(new Edge(data.get(i), data.get(i + 1), data.get(i + 2)));
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public final class EdmondsBlossomAlgorithm {
|
|||||||
* @param vertexCount The number of vertices in the graph.
|
* @param vertexCount The number of vertices in the graph.
|
||||||
* @return A list of matched pairs of vertices.
|
* @return A list of matched pairs of vertices.
|
||||||
*/
|
*/
|
||||||
public static List<int[]> maximumMatching(List<int[]> edges, int vertexCount) {
|
public static List<int[]> maximumMatching(Iterable<int[]> edges, int vertexCount) {
|
||||||
List<List<Integer>> graph = new ArrayList<>(vertexCount);
|
List<List<Integer>> graph = new ArrayList<>(vertexCount);
|
||||||
|
|
||||||
// Initialize each vertex's adjacency list.
|
// Initialize each vertex's adjacency list.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.datastructures.lists;
|
package com.thealgorithms.datastructures.lists;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +39,7 @@ public final class MergeSortedArrayList {
|
|||||||
* @param listB the second list to merge
|
* @param listB the second list to merge
|
||||||
* @param listC the result list after merging
|
* @param listC the result list after merging
|
||||||
*/
|
*/
|
||||||
public static void merge(List<Integer> listA, List<Integer> listB, List<Integer> listC) {
|
public static void merge(List<Integer> listA, List<Integer> listB, Collection<Integer> listC) {
|
||||||
int pa = 0;
|
int pa = 0;
|
||||||
/* the index of listA */
|
/* the index of listA */
|
||||||
int pb = 0;
|
int pb = 0;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.geometry;
|
package com.thealgorithms.geometry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -89,7 +90,7 @@ public final class ConvexHull {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void constructHull(List<Point> points, Point left, Point right, Set<Point> convexSet) {
|
private static void constructHull(Collection<Point> points, Point left, Point right, Set<Point> convexSet) {
|
||||||
if (!points.isEmpty()) {
|
if (!points.isEmpty()) {
|
||||||
Point extremePoint = null;
|
Point extremePoint = null;
|
||||||
int extremePointDistance = Integer.MIN_VALUE;
|
int extremePointDistance = Integer.MIN_VALUE;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for circular convolution of two discrete signals using the convolution
|
* Class for circular convolution of two discrete signals using the convolution
|
||||||
@ -19,7 +20,7 @@ public final class CircularConvolutionFFT {
|
|||||||
* @param x The signal to be padded.
|
* @param x The signal to be padded.
|
||||||
* @param newSize The new size of the signal.
|
* @param newSize The new size of the signal.
|
||||||
*/
|
*/
|
||||||
private static void padding(ArrayList<FFT.Complex> x, int newSize) {
|
private static void padding(Collection<FFT.Complex> x, int newSize) {
|
||||||
if (x.size() < newSize) {
|
if (x.size() < newSize) {
|
||||||
int diff = newSize - x.size();
|
int diff = newSize - x.size();
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for linear convolution of two discrete signals using the convolution
|
* Class for linear convolution of two discrete signals using the convolution
|
||||||
@ -19,7 +20,7 @@ public final class ConvolutionFFT {
|
|||||||
* @param x The signal to be padded.
|
* @param x The signal to be padded.
|
||||||
* @param newSize The new size of the signal.
|
* @param newSize The new size of the signal.
|
||||||
*/
|
*/
|
||||||
private static void padding(ArrayList<FFT.Complex> x, int newSize) {
|
private static void padding(Collection<FFT.Complex> x, int newSize) {
|
||||||
if (x.size() < newSize) {
|
if (x.size() < newSize) {
|
||||||
int diff = newSize - x.size();
|
int diff = newSize - x.size();
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,7 +275,7 @@ public final class FFT {
|
|||||||
*
|
*
|
||||||
* @param x The ArrayList to be padded.
|
* @param x The ArrayList to be padded.
|
||||||
*/
|
*/
|
||||||
private static void paddingPowerOfTwo(ArrayList<Complex> x) {
|
private static void paddingPowerOfTwo(Collection<Complex> x) {
|
||||||
int n = 1;
|
int n = 1;
|
||||||
int oldSize = x.size();
|
int oldSize = x.size();
|
||||||
while (n < oldSize) {
|
while (n < oldSize) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal
|
* Class for calculating the Fast Fourier Transform (FFT) of a discrete signal
|
||||||
@ -25,7 +26,7 @@ public final class FFTBluestein {
|
|||||||
* IFFT of signal x.
|
* IFFT of signal x.
|
||||||
* @param inverse True if you want to find the inverse FFT.
|
* @param inverse True if you want to find the inverse FFT.
|
||||||
*/
|
*/
|
||||||
public static void fftBluestein(ArrayList<FFT.Complex> x, boolean inverse) {
|
public static void fftBluestein(List<FFT.Complex> x, boolean inverse) {
|
||||||
int n = x.size();
|
int n = x.size();
|
||||||
int bnSize = 2 * n - 1;
|
int bnSize = 2 * n - 1;
|
||||||
int direction = inverse ? -1 : 1;
|
int direction = inverse ? -1 : 1;
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.thealgorithms.maths;
|
package com.thealgorithms.maths;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class Gaussian {
|
public final class Gaussian {
|
||||||
private Gaussian() {
|
private Gaussian() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix) {
|
public static ArrayList<Double> gaussian(int matSize, List<Double> matrix) {
|
||||||
int i;
|
int i;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.thealgorithms.maths;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
import org.apache.commons.lang3.tuple.MutablePair;
|
import org.apache.commons.lang3.tuple.MutablePair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +65,7 @@ public class NthUglyNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long computeCandidate(final MutablePair<Integer, Integer> entry) {
|
private long computeCandidate(final Map.Entry<Integer, Integer> entry) {
|
||||||
return entry.getKey() * uglyNumbers.get(entry.getValue());
|
return entry.getKey() * uglyNumbers.get(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ public final class MedianOfMatrix {
|
|||||||
private MedianOfMatrix() {
|
private MedianOfMatrix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int median(List<List<Integer>> matrix) {
|
public static int median(Iterable<List<Integer>> matrix) {
|
||||||
// Flatten the matrix into a 1D list
|
// Flatten the matrix into a 1D list
|
||||||
List<Integer> linear = new ArrayList<>();
|
List<Integer> linear = new ArrayList<>();
|
||||||
for (List<Integer> row : matrix) {
|
for (List<Integer> row : matrix) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.thealgorithms.misc;
|
package com.thealgorithms.misc;
|
||||||
|
|
||||||
import com.thealgorithms.datastructures.lists.SinglyLinkedList;
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,8 +14,8 @@ public final class PalindromeSinglyLinkedList {
|
|||||||
private PalindromeSinglyLinkedList() {
|
private PalindromeSinglyLinkedList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPalindrome(final SinglyLinkedList linkedList) {
|
public static boolean isPalindrome(final Iterable linkedList) {
|
||||||
Stack<Integer> linkedListValues = new Stack<>();
|
var linkedListValues = new Stack<>();
|
||||||
|
|
||||||
for (final var x : linkedList) {
|
for (final var x : linkedList) {
|
||||||
linkedListValues.push(x);
|
linkedListValues.push(x);
|
||||||
|
@ -7,6 +7,7 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,7 +126,7 @@ public final class KochSnowflake {
|
|||||||
* applied.
|
* applied.
|
||||||
* @return The transformed vectors after the iteration-step.
|
* @return The transformed vectors after the iteration-step.
|
||||||
*/
|
*/
|
||||||
private static ArrayList<Vector2> iterationStep(ArrayList<Vector2> vectors) {
|
private static ArrayList<Vector2> iterationStep(List<Vector2> vectors) {
|
||||||
ArrayList<Vector2> newVectors = new ArrayList<Vector2>();
|
ArrayList<Vector2> newVectors = new ArrayList<Vector2>();
|
||||||
for (int i = 0; i < vectors.size() - 1; i++) {
|
for (int i = 0; i < vectors.size() - 1; i++) {
|
||||||
Vector2 startVector = vectors.get(i);
|
Vector2 startVector = vectors.get(i);
|
||||||
|
@ -2,6 +2,7 @@ package com.thealgorithms.scheduling;
|
|||||||
|
|
||||||
import com.thealgorithms.devutils.entities.ProcessDetails;
|
import com.thealgorithms.devutils.entities.ProcessDetails;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
@ -15,7 +16,7 @@ public class PreemptivePriorityScheduling {
|
|||||||
protected final List<ProcessDetails> processes;
|
protected final List<ProcessDetails> processes;
|
||||||
protected final List<String> ganttChart;
|
protected final List<String> ganttChart;
|
||||||
|
|
||||||
public PreemptivePriorityScheduling(List<ProcessDetails> processes) {
|
public PreemptivePriorityScheduling(Collection<ProcessDetails> processes) {
|
||||||
this.processes = new ArrayList<>(processes);
|
this.processes = new ArrayList<>(processes);
|
||||||
this.ganttChart = new ArrayList<>();
|
this.ganttChart = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.thealgorithms.scheduling;
|
|||||||
|
|
||||||
import com.thealgorithms.devutils.entities.ProcessDetails;
|
import com.thealgorithms.devutils.entities.ProcessDetails;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of Shortest Job First Algorithm: The algorithm allows the waiting process with the
|
* Implementation of Shortest Job First Algorithm: The algorithm allows the waiting process with the
|
||||||
@ -87,7 +88,7 @@ public class SJFScheduling {
|
|||||||
* @return returns the process' with the shortest burst time OR NULL if there are no ready
|
* @return returns the process' with the shortest burst time OR NULL if there are no ready
|
||||||
* processes
|
* processes
|
||||||
*/
|
*/
|
||||||
private ProcessDetails findShortestJob(ArrayList<ProcessDetails> readyProcesses) {
|
private ProcessDetails findShortestJob(List<ProcessDetails> readyProcesses) {
|
||||||
if (readyProcesses.isEmpty()) {
|
if (readyProcesses.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.thealgorithms.scheduling.diskscheduling;
|
package com.thealgorithms.scheduling.diskscheduling;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +25,7 @@ public class SSFScheduling {
|
|||||||
this.currentPosition = currentPosition;
|
this.currentPosition = currentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> execute(List<Integer> requests) {
|
public List<Integer> execute(Collection<Integer> requests) {
|
||||||
List<Integer> result = new ArrayList<>(requests);
|
List<Integer> result = new ArrayList<>(requests);
|
||||||
List<Integer> orderedRequests = new ArrayList<>();
|
List<Integer> orderedRequests = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class BucketSort implements SortAlgorithm {
|
|||||||
* @param <T> the type of elements in the array
|
* @param <T> the type of elements in the array
|
||||||
* @return the sorted array
|
* @return the sorted array
|
||||||
*/
|
*/
|
||||||
private <T extends Comparable<T>> T[] concatenateBuckets(List<List<T>> buckets, T[] array) {
|
private <T extends Comparable<T>> T[] concatenateBuckets(Iterable<List<T>> buckets, T[] array) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (List<T> bucket : buckets) {
|
for (List<T> bucket : buckets) {
|
||||||
Collections.sort(bucket);
|
Collections.sort(bucket);
|
||||||
|
@ -72,7 +72,7 @@ public class PatienceSort implements SortAlgorithm {
|
|||||||
* @param <T> the type of elements in the piles, must be comparable
|
* @param <T> the type of elements in the piles, must be comparable
|
||||||
* @return a priority queue containing the top element of each pile
|
* @return a priority queue containing the top element of each pile
|
||||||
*/
|
*/
|
||||||
private static <T extends Comparable<T>> PriorityQueue<PileNode<T>> mergePiles(final List<List<T>> piles) {
|
private static <T extends Comparable<T>> PriorityQueue<PileNode<T>> mergePiles(final Iterable<List<T>> piles) {
|
||||||
PriorityQueue<PileNode<T>> pq = new PriorityQueue<>();
|
PriorityQueue<PileNode<T>> pq = new PriorityQueue<>();
|
||||||
for (List<T> pile : piles) {
|
for (List<T> pile : piles) {
|
||||||
pq.add(new PileNode<>(pile.removeLast(), pile));
|
pq.add(new PileNode<>(pile.removeLast(), pile));
|
||||||
|
@ -78,7 +78,7 @@ public final class PigeonholeSort {
|
|||||||
* @param array the array to be sorted
|
* @param array the array to be sorted
|
||||||
* @param pigeonHoles the populated pigeonholes
|
* @param pigeonHoles the populated pigeonholes
|
||||||
*/
|
*/
|
||||||
private static void collectFromPigeonHoles(int[] array, List<List<Integer>> pigeonHoles) {
|
private static void collectFromPigeonHoles(int[] array, Iterable<List<Integer>> pigeonHoles) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (final var pigeonHole : pigeonHoles) {
|
for (final var pigeonHole : pigeonHoles) {
|
||||||
for (final int element : pigeonHole) {
|
for (final int element : pigeonHole) {
|
||||||
|
@ -51,7 +51,7 @@ public class TreeSort implements SortAlgorithm {
|
|||||||
return unsortedArray;
|
return unsortedArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Comparable<T>> List<T> doTreeSortList(List<T> unsortedList) {
|
private <T extends Comparable<T>> List<T> doTreeSortList(Iterable<T> unsortedList) {
|
||||||
// create a generic BST tree
|
// create a generic BST tree
|
||||||
BSTRecursiveGeneric<T> tree = new BSTRecursiveGeneric<T>();
|
BSTRecursiveGeneric<T> tree = new BSTRecursiveGeneric<T>();
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.thealgorithms.strings;
|
package com.thealgorithms.strings;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ public final class WordLadder {
|
|||||||
* @param wordList a list of words that can be used in the transformation sequence
|
* @param wordList a list of words that can be used in the transformation sequence
|
||||||
* @return the number of words in the shortest transformation sequence, or 0 if no such sequence exists
|
* @return the number of words in the shortest transformation sequence, or 0 if no such sequence exists
|
||||||
*/
|
*/
|
||||||
public static int ladderLength(String beginWord, String endWord, List<String> wordList) {
|
public static int ladderLength(String beginWord, String endWord, Collection<String> wordList) {
|
||||||
Set<String> wordSet = new HashSet<>(wordList);
|
Set<String> wordSet = new HashSet<>(wordList);
|
||||||
|
|
||||||
if (!wordSet.contains(endWord)) {
|
if (!wordSet.contains(endWord)) {
|
||||||
|
@ -183,7 +183,7 @@ public class BoruvkaAlgorithmTest {
|
|||||||
* @param result list of edges in the Minimum Spanning Tree
|
* @param result list of edges in the Minimum Spanning Tree
|
||||||
* @return the total weight of the Minimum Spanning Tree
|
* @return the total weight of the Minimum Spanning Tree
|
||||||
*/
|
*/
|
||||||
int computeTotalWeight(final List<BoruvkaAlgorithm.Edge> result) {
|
int computeTotalWeight(final Iterable<BoruvkaAlgorithm.Edge> result) {
|
||||||
int totalWeight = 0;
|
int totalWeight = 0;
|
||||||
for (final var edge : result) {
|
for (final var edge : result) {
|
||||||
totalWeight += edge.weight;
|
totalWeight += edge.weight;
|
||||||
|
@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -25,7 +26,7 @@ public class EdmondsBlossomAlgorithmTest {
|
|||||||
* @param matching List of matched pairs returned by the algorithm.
|
* @param matching List of matched pairs returned by the algorithm.
|
||||||
* @return A sorted 2D array of matching pairs.
|
* @return A sorted 2D array of matching pairs.
|
||||||
*/
|
*/
|
||||||
private int[][] convertMatchingToArray(List<int[]> matching) {
|
private int[][] convertMatchingToArray(Collection<int[]> matching) {
|
||||||
// Convert the list of pairs into an array
|
// Convert the list of pairs into an array
|
||||||
int[][] result = matching.toArray(new int[0][]);
|
int[][] result = matching.toArray(new int[0][]);
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@ -44,7 +45,7 @@ class WordBoggleTest {
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideSpecialCases")
|
@MethodSource("provideSpecialCases")
|
||||||
void testBoggleBoardSpecialCases(char[][] specialBoard, String[] words, List<String> expectedWords, String testDescription) {
|
void testBoggleBoardSpecialCases(char[][] specialBoard, String[] words, Collection<String> expectedWords, String testDescription) {
|
||||||
List<String> result = WordBoggle.boggleBoard(specialBoard, words);
|
List<String> result = WordBoggle.boggleBoard(specialBoard, words);
|
||||||
assertEquals(expectedWords.size(), result.size(), "Test failed for: " + testDescription);
|
assertEquals(expectedWords.size(), result.size(), "Test failed for: " + testDescription);
|
||||||
assertTrue(expectedWords.containsAll(result), "Test failed for: " + testDescription);
|
assertTrue(expectedWords.containsAll(result), "Test failed for: " + testDescription);
|
||||||
|
@ -3,6 +3,7 @@ package com.thealgorithms.scheduling;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import com.thealgorithms.devutils.entities.ProcessDetails;
|
import com.thealgorithms.devutils.entities.ProcessDetails;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
@ -17,7 +18,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
|||||||
class PreemptivePrioritySchedulingTest {
|
class PreemptivePrioritySchedulingTest {
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("provideProcessesAndExpectedSchedules")
|
@MethodSource("provideProcessesAndExpectedSchedules")
|
||||||
void testPreemptivePriorityScheduling(List<ProcessDetails> processes, List<String> expectedSchedule) {
|
void testPreemptivePriorityScheduling(Collection<ProcessDetails> processes, List<String> expectedSchedule) {
|
||||||
PreemptivePriorityScheduling scheduler = new PreemptivePriorityScheduling(processes);
|
PreemptivePriorityScheduling scheduler = new PreemptivePriorityScheduling(processes);
|
||||||
scheduler.scheduleProcesses();
|
scheduler.scheduleProcesses();
|
||||||
assertEquals(expectedSchedule, scheduler.ganttChart);
|
assertEquals(expectedSchedule, scheduler.ganttChart);
|
||||||
|
@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -225,7 +226,7 @@ class QuickSelectTest {
|
|||||||
return RANDOM.ints(n, ASCII_A, ASCII_Z).mapToObj(i -> (char) i).collect(Collectors.toList());
|
return RANDOM.ints(n, ASCII_A, ASCII_Z).mapToObj(i -> (char) i).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends Comparable<T>> List<T> getSortedCopyOfList(List<T> list) {
|
private static <T extends Comparable<T>> List<T> getSortedCopyOfList(Collection<T> list) {
|
||||||
return list.stream().sorted().collect(Collectors.toList());
|
return list.stream().sorted().collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user