mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 15:02:46 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -1,48 +1,47 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ArrayLeftRotationTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int[] arr = {3};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 3);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int[] arr = { 3 };
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 3);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForZeroStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 0);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
@Test
|
||||
void testForZeroStep() {
|
||||
int[] arr = { 3, 1, 5, 8, 6 };
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 0);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEqualSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 5);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
@Test
|
||||
void testForEqualSizeStep() {
|
||||
int[] arr = { 3, 1, 5, 8, 6 };
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 5);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForLowerSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int n = 2;
|
||||
int[] expected = {5, 8, 6, 3, 1};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, n);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
@Test
|
||||
void testForLowerSizeStep() {
|
||||
int[] arr = { 3, 1, 5, 8, 6 };
|
||||
int n = 2;
|
||||
int[] expected = { 5, 8, 6, 3, 1 };
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, n);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForHigherSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int n = 7;
|
||||
int[] expected = {5, 8, 6, 3, 1};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, n);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
void testForHigherSizeStep() {
|
||||
int[] arr = { 3, 1, 5, 8, 6 };
|
||||
int n = 7;
|
||||
int[] expected = { 5, 8, 6, 3, 1 };
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, n);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,69 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* author Alexandros Lemonaris
|
||||
*/
|
||||
class BestFitCPUTest {
|
||||
int [] sizeOfBlocks;
|
||||
int [] sizeOfProcesses;
|
||||
|
||||
int[] sizeOfBlocks;
|
||||
int[] sizeOfProcesses;
|
||||
ArrayList<Integer> memAllocation = new ArrayList<>();
|
||||
ArrayList<Integer> testMemAllocation ;
|
||||
MemoryManagementAlgorithms bestFit = new BestFitCPU();
|
||||
ArrayList<Integer> testMemAllocation;
|
||||
MemoryManagementAlgorithms bestFit = new BestFitCPU();
|
||||
|
||||
@Test
|
||||
void testFitForUseOfOneBlock() {
|
||||
//test1 - 2 processes shall fit to one block instead of using a different block each
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 5, 15, 2};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 5, 15, 2 };
|
||||
memAllocation = bestFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(3, 0, 2, 2)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(3, 0, 2, 2));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForEqualProcecesses() {
|
||||
//test2
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 10, 10, 10};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 10, 10, 10 };
|
||||
memAllocation = bestFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(3, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(3, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForNoEmptyBlockCell() {
|
||||
//test3 for more processes than blocks - no empty space left to none of the blocks
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 12, 10, 7};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 12, 10, 7 };
|
||||
memAllocation = bestFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, 2)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, 2));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForSameInputDifferentQuery() {
|
||||
//test4 for more processes than blocks - one element does not fit due to input series
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 7, 10, 12};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 7, 10, 12 };
|
||||
memAllocation = bestFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForMoreBlocksNoFit() {
|
||||
//test5 for more blocks than processes
|
||||
sizeOfBlocks = new int[] {5, 4, -1, 3, 6};
|
||||
sizeOfProcesses = new int [] {10, 11};
|
||||
sizeOfBlocks = new int[] { 5, 4, -1, 3, 6 };
|
||||
sizeOfProcesses = new int[] { 10, 11 };
|
||||
memAllocation = bestFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList( -255, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(-255, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,58 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.datastructures.stacks.CalculateMaxOfMin;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CalculateMaxOfMinTest {
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { 10, 20, 30, 50, 10, 70, 30 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 5, 3, 2, 6, 3, 2, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 6);
|
||||
}
|
||||
@Test
|
||||
void testForOneElement() {
|
||||
int a[] = { 10, 20, 30, 50, 10, 70, 30 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 10, 10, 10, 10, 10, 10, 10 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 10);
|
||||
}
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 5, 3, 2, 6, 3, 2, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 6);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 70, 60, 50, 40, 30, 20 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 10, 10, 10, 10, 10, 10, 10 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 50 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 50);
|
||||
}
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 70, 60, 50, 40, 30, 20 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 70);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 1, 4, 7, 9, 2, 4, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 9);
|
||||
}
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 50 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { -1, -5, -7, -9, -12, -14 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == -1);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 1, 4, 7, 9, 2, 4, 6 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == 9);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { -1, -5, -7, -9, -12, -14 };
|
||||
int k = CalculateMaxOfMin.calculateMaxOfMin(a);
|
||||
assertTrue(k == -1);
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,57 @@
|
||||
package com.thealgorithms.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.dynamicprogramming.CountFriendsPairing;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CountFriendsPairingTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement()
|
||||
{
|
||||
int a[] = {1,2,2};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(3,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements()
|
||||
{
|
||||
int a[] = {1,2,2,3};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(4,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(5,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3,4};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(6,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3,4,4};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(7,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3,4,4,4};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(8,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3,4,4,4,5};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(9,a));
|
||||
void testForOneElement() {
|
||||
int a[] = { 1, 2, 2 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(3, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements()
|
||||
{
|
||||
int a[] = {1,2,2,3,3,4,4,4,5,5};
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(10,a));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 1, 2, 2, 3 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(4, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(5, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(6, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(7, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(8, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4, 5 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(9, a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 1, 2, 2, 3, 3, 4, 4, 4, 5, 5 };
|
||||
assertTrue(CountFriendsPairing.countFriendsPairing(10, a));
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,69 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* author Alexandros Lemonaris
|
||||
*/
|
||||
class FirstFitCPUTest {
|
||||
int [] sizeOfBlocks;
|
||||
int [] sizeOfProcesses;
|
||||
|
||||
int[] sizeOfBlocks;
|
||||
int[] sizeOfProcesses;
|
||||
ArrayList<Integer> memAllocation = new ArrayList<>();
|
||||
ArrayList<Integer> testMemAllocation ;
|
||||
MemoryManagementAlgorithms firstFit = new FirstFitCPU();
|
||||
ArrayList<Integer> testMemAllocation;
|
||||
MemoryManagementAlgorithms firstFit = new FirstFitCPU();
|
||||
|
||||
@Test
|
||||
void testFitForUseOfOneBlock() {
|
||||
//test1 - no use of one block for two processes
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 5, 15, 2};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 5, 15, 2 };
|
||||
memAllocation = firstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(1, 0, 2, 1)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(1, 0, 2, 1));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForEqualProcecesses() {
|
||||
//test2
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 10, 10, 10};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 10, 10, 10 };
|
||||
memAllocation = firstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(1, 2, 3, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(1, 2, 3, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForNoEmptyBlockCell() {
|
||||
//test3 for more processes than blocks - no empty space left to none of the blocks
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 12, 10, 7};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 12, 10, 7 };
|
||||
memAllocation = firstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, 2)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, 2));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForSameInputDifferentQuery() {
|
||||
//test4 for more processes than blocks - one element does not fit due to input series
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 7, 10, 12};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 7, 10, 12 };
|
||||
memAllocation = firstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForMoreBlocksNoFit() {
|
||||
//test5 for more blocks than processes
|
||||
sizeOfBlocks = new int[] {5, 4, -1, 3, 6};
|
||||
sizeOfProcesses = new int [] {10, 11};
|
||||
sizeOfBlocks = new int[] { 5, 4, -1, 3, 6 };
|
||||
sizeOfProcesses = new int[] { 10, 11 };
|
||||
memAllocation = firstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList( -255, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(-255, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +1,57 @@
|
||||
package com.thealgorithms.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.dynamicprogramming.KadaneAlgorithm;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class KadaneAlogrithmTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement()
|
||||
{
|
||||
int a[]={-1};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements()
|
||||
{
|
||||
int a[]={-2,1};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements()
|
||||
{
|
||||
int a[]={5,3,12};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,20));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements()
|
||||
{
|
||||
int a[]={-1,-3,-7,-4};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements()
|
||||
{
|
||||
int a[]={4,5,3,0,2};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,14));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForSixElements()
|
||||
{
|
||||
int a[]={-43,-45,47,12,87,-13};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,146));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements()
|
||||
{
|
||||
int a[]={9,8,2,23,13,6,7};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,68));
|
||||
void testForOneElement() {
|
||||
int a[] = { -1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements()
|
||||
{
|
||||
int a[]={9,-5,-5,-2,4,5,0,1};
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a,10));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { -2, 1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 5, 3, 12 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 20));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { -1, -3, -7, -4 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 4, 5, 3, 0, 2 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 14));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { -43, -45, 47, 12, 87, -13 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 146));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 9, 8, 2, 23, 13, 6, 7 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 68));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 9, -5, -5, -2, 4, 5, 0, 1 };
|
||||
assertTrue(KadaneAlgorithm.max_Sum(a, 10));
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,57 @@
|
||||
package com.thealgorithms.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.thealgorithms.sorts.LinkList_Sort;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.sorts.LinkList_Sort;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LinkListSortTest {
|
||||
|
||||
@Test
|
||||
void testForOneElement()
|
||||
{
|
||||
int a[]={56};
|
||||
assertTrue(LinkList_Sort.isSorted(a,2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements()
|
||||
{
|
||||
int a[]={6,4};
|
||||
assertTrue(LinkList_Sort.isSorted(a,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements()
|
||||
{
|
||||
int a[]={875,253,12};
|
||||
assertTrue(LinkList_Sort.isSorted(a,3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements()
|
||||
{
|
||||
int a[]={86,32,87,13};
|
||||
assertTrue(LinkList_Sort.isSorted(a,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements()
|
||||
{
|
||||
int a[]={6,5,3,0,9};
|
||||
assertTrue(LinkList_Sort.isSorted(a,1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForSixElements()
|
||||
{
|
||||
int a[]={9,65,432,32,47,327};
|
||||
assertTrue(LinkList_Sort.isSorted(a,3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements()
|
||||
{
|
||||
int a[]={6,4,2,1,3,6,7};
|
||||
assertTrue(LinkList_Sort.isSorted(a,1));
|
||||
void testForOneElement() {
|
||||
int a[] = { 56 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements()
|
||||
{
|
||||
int a[]={123,234,145,764,322,367,768,34};
|
||||
assertTrue(LinkList_Sort.isSorted(a,2));
|
||||
}
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
int a[] = { 6, 4 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
int a[] = { 875, 253, 12 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
int a[] = { 86, 32, 87, 13 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
int a[] = { 6, 5, 3, 0, 9 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
int a[] = { 9, 65, 432, 32, 47, 327 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
int a[] = { 6, 4, 2, 1, 3, 6, 7 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
int a[] = { 123, 234, 145, 764, 322, 367, 768, 34 };
|
||||
assertTrue(LinkList_Sort.isSorted(a, 2));
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,49 @@
|
||||
package com.thealgorithms.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.dynamicprogramming.NewManShanksPrime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class NewManShanksPrimeTest {
|
||||
@Test
|
||||
void testOne()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(1,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTwo()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(2,3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThree()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(3,7));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFour()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(4,17));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFive()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(5,41));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSix()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(6,99));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSeven()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(7,239));
|
||||
void testOne() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEight()
|
||||
{
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(8,577));
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
void testTwo() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThree() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(3, 7));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFour() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(4, 17));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFive() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(5, 41));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSix() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(6, 99));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSeven() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(7, 239));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEight() {
|
||||
assertTrue(NewManShanksPrime.nthManShanksPrime(8, 577));
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +1,69 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* author Alexandros Lemonaris
|
||||
*/
|
||||
class NextFitCPUTest {
|
||||
int [] sizeOfBlocks;
|
||||
int [] sizeOfProcesses;
|
||||
|
||||
int[] sizeOfBlocks;
|
||||
int[] sizeOfProcesses;
|
||||
ArrayList<Integer> memAllocation = new ArrayList<>();
|
||||
ArrayList<Integer> testMemAllocation ;
|
||||
MemoryManagementAlgorithms nextFit = new NextFit();
|
||||
ArrayList<Integer> testMemAllocation;
|
||||
MemoryManagementAlgorithms nextFit = new NextFit();
|
||||
|
||||
@Test
|
||||
void testFitForUseOfOneBlock() {
|
||||
//test1 - third process does not fit because of algorithms procedure
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 5, 15, 2};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 5, 15, 2 };
|
||||
memAllocation = nextFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(1, 2, -255, 2)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(1, 2, -255, 2));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForEqualProcecesses() {
|
||||
//test2
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 10, 10, 10};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 10, 10, 10 };
|
||||
memAllocation = nextFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(1, 2, 3, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(1, 2, 3, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForNoEmptyBlockCell() {
|
||||
//test3 for more processes than blocks - no empty space left to none of the blocks
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 12, 10, 7};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 12, 10, 7 };
|
||||
memAllocation = nextFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, 2)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, 2));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForSameInputDifferentQuery() {
|
||||
//test4 for more processes than blocks - one element does not fit due to input series
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 7, 10, 12};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 7, 10, 12 };
|
||||
memAllocation = nextFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(0, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(0, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForMoreBlocksNoFit() {
|
||||
//test5 for more blocks than processes
|
||||
sizeOfBlocks = new int[] {5, 4, -1, 3, 6};
|
||||
sizeOfProcesses = new int [] {10, 11};
|
||||
sizeOfBlocks = new int[] { 5, 4, -1, 3, 6 };
|
||||
sizeOfProcesses = new int[] { 10, 11 };
|
||||
memAllocation = nextFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList( -255, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(-255, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,43 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PasswordGenTest {
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void failGenerationWithSameMinMaxLengthTest() {
|
||||
int length = 10;
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
PasswordGen.generatePassword(length, length);
|
||||
});
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
PasswordGen.generatePassword(length, length);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateOneCharacterPassword() {
|
||||
String tempPassword = PasswordGen.generatePassword(1, 2);
|
||||
assertTrue(tempPassword.length()==1);
|
||||
assertTrue(tempPassword.length() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failGenerationWithMinLengthSmallerThanMaxLengthTest() {
|
||||
int minLength = 10;
|
||||
int maxLength = 5;
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
PasswordGen.generatePassword(minLength, maxLength);
|
||||
});
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
PasswordGen.generatePassword(minLength, maxLength);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePasswordNonEmptyTest() {
|
||||
String tempPassword = PasswordGen.generatePassword(8, 16);
|
||||
assertTrue(tempPassword.length()!=0);
|
||||
assertTrue(tempPassword.length() != 0);
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,49 @@
|
||||
package com.thealgorithms.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.thealgorithms.dynamicprogramming.UniquePaths;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UniquePathsTests {
|
||||
|
||||
@Test
|
||||
void testForOneElement()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths(3,7,28));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwoElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths(3,2,3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths(3,3,6));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths(4,6,56));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths2(3,5,15));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths2(6,2,6));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths2(5,9,495));
|
||||
void testForOneElement() {
|
||||
assertTrue(UniquePaths.uniquePaths(3, 7, 28));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements()
|
||||
{
|
||||
assertTrue(UniquePaths.uniquePaths2(4,8,120));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testForTwoElements() {
|
||||
assertTrue(UniquePaths.uniquePaths(3, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForThreeElements() {
|
||||
assertTrue(UniquePaths.uniquePaths(3, 3, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFourElements() {
|
||||
assertTrue(UniquePaths.uniquePaths(4, 6, 56));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFiveElements() {
|
||||
assertTrue(UniquePaths.uniquePaths2(3, 5, 15));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSixElements() {
|
||||
assertTrue(UniquePaths.uniquePaths2(6, 2, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForSevenElements() {
|
||||
assertTrue(UniquePaths.uniquePaths2(5, 9, 495));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEightElements() {
|
||||
assertTrue(UniquePaths.uniquePaths2(4, 8, 120));
|
||||
}
|
||||
}
|
||||
|
@ -1,87 +1,80 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* author Alexandros Lemonaris
|
||||
*/
|
||||
class WorstFitCPUTest {
|
||||
int [] sizeOfBlocks;
|
||||
int [] sizeOfProcesses;
|
||||
|
||||
int[] sizeOfBlocks;
|
||||
int[] sizeOfProcesses;
|
||||
ArrayList<Integer> memAllocation = new ArrayList<>();
|
||||
ArrayList<Integer> testMemAllocation ;
|
||||
MemoryManagementAlgorithms worstFit = new WorstFitCPU();
|
||||
ArrayList<Integer> testMemAllocation;
|
||||
MemoryManagementAlgorithms worstFit = new WorstFitCPU();
|
||||
|
||||
@Test
|
||||
void testFitForUseOfOneBlock() {
|
||||
//test1
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 5, 15, 2};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 5, 15, 2 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(2, 1, -255, 3)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(2, 1, -255, 3));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForEqualProcecesses() {
|
||||
//test2
|
||||
sizeOfBlocks = new int[]{5, 12, 17, 10};
|
||||
sizeOfProcesses = new int[]{10, 10, 10, 10};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17, 10 };
|
||||
sizeOfProcesses = new int[] { 10, 10, 10, 10 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(2, 1, 3, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(2, 1, 3, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForNoEmptyBlockCell() {
|
||||
//test3 - could suits best, bad use of memory allocation due to worstFit algorithm
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 12, 10, 7};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 12, 10, 7 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(2, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(2, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForSameInputDifferentQuery() {
|
||||
//test4 same example different series - same results
|
||||
sizeOfBlocks = new int[]{5, 12, 17};
|
||||
sizeOfProcesses = new int[]{5, 7, 10, 12};
|
||||
sizeOfBlocks = new int[] { 5, 12, 17 };
|
||||
sizeOfProcesses = new int[] { 5, 7, 10, 12 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList(2, 1, 2, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(2, 1, 2, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitForMoreBlocksNoFit() {
|
||||
//test5 for more blocks than processes
|
||||
sizeOfBlocks = new int[] {5, 4, -1, 3, 6};
|
||||
sizeOfProcesses = new int [] {10, 11};
|
||||
sizeOfBlocks = new int[] { 5, 4, -1, 3, 6 };
|
||||
sizeOfProcesses = new int[] { 10, 11 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList( -255, -255)
|
||||
);
|
||||
testMemAllocation = new ArrayList<>(Arrays.asList(-255, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFitBadCase() {
|
||||
//test6 for only two process fit
|
||||
sizeOfBlocks = new int[] {7, 17, 7, 5, 6};
|
||||
sizeOfProcesses = new int [] {8, 10, 10, 8, 8, 8};
|
||||
sizeOfBlocks = new int[] { 7, 17, 7, 5, 6 };
|
||||
sizeOfProcesses = new int[] { 8, 10, 10, 8, 8, 8 };
|
||||
memAllocation = worstFit.fitProcess(sizeOfBlocks, sizeOfProcesses);
|
||||
testMemAllocation = new ArrayList<>(
|
||||
Arrays.asList( 1, -255, -255, 1, -255, -255)
|
||||
);
|
||||
testMemAllocation =
|
||||
new ArrayList<>(Arrays.asList(1, -255, -255, 1, -255, -255));
|
||||
assertEquals(testMemAllocation, memAllocation);
|
||||
}
|
||||
}
|
||||
|
@ -5,23 +5,23 @@ import org.assertj.core.api.ThrowableTypeAssert;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
public class HammingDistanceTest {
|
||||
|
||||
HammingDistance hd;
|
||||
|
||||
@BeforeEach
|
||||
void initialize(){
|
||||
void initialize() {
|
||||
hd = new HammingDistance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkForDifferentBits(){
|
||||
String senderBits = "000", receiverBits = "011";
|
||||
public void checkForDifferentBits() {
|
||||
String senderBits = "000", receiverBits = "011";
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
Assertions.assertThat(answer).isEqualTo(2);
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
|
||||
1 0 1 0 1
|
||||
1 1 1 1 0
|
||||
@ -31,46 +31,49 @@ public class HammingDistanceTest {
|
||||
|
||||
*/
|
||||
@Test
|
||||
public void checkForDifferentBitsLength(){
|
||||
String senderBits = "10101", receiverBits = "11110";
|
||||
public void checkForDifferentBitsLength() {
|
||||
String senderBits = "10101", receiverBits = "11110";
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
Assertions.assertThat(answer).isEqualTo(3);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkForSameBits(){
|
||||
public void checkForSameBits() {
|
||||
String senderBits = "111", receiverBits = "111";
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
Assertions.assertThat(answer).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkForLongDataBits(){
|
||||
String senderBits = "10010101101010000100110100", receiverBits = "00110100001011001100110101";
|
||||
public void checkForLongDataBits() {
|
||||
String senderBits = "10010101101010000100110100", receiverBits =
|
||||
"00110100001011001100110101";
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
Assertions.assertThat(answer).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mismatchDataBits(){
|
||||
public void mismatchDataBits() {
|
||||
String senderBits = "100010", receiverBits = "00011";
|
||||
|
||||
Exception ex = org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () ->{
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
});
|
||||
Exception ex = org.junit.jupiter.api.Assertions.assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
int answer = hd.getHammingDistanceBetweenBits(
|
||||
senderBits,
|
||||
receiverBits
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Assertions.assertThat(ex.getMessage()).contains("bits should be same");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkForLongDataBitsSame(){
|
||||
String senderBits = "10010101101010000100110100", receiverBits = "10010101101010000100110100";
|
||||
public void checkForLongDataBitsSame() {
|
||||
String senderBits = "10010101101010000100110100", receiverBits =
|
||||
"10010101101010000100110100";
|
||||
int answer = hd.getHammingDistanceBetweenBits(senderBits, receiverBits);
|
||||
Assertions.assertThat(answer).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,13 +3,15 @@ package com.thealgorithms.others;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class countSetBitsTest {
|
||||
|
||||
@Test
|
||||
void testSetBits(){
|
||||
countSetBits csb= new countSetBits();
|
||||
assertEquals(1L,csb.countsetBits(16));
|
||||
void testSetBits() {
|
||||
countSetBits csb = new countSetBits();
|
||||
assertEquals(1L, csb.countsetBits(16));
|
||||
assertEquals(4, csb.countsetBits(15));
|
||||
assertEquals(5, csb.countsetBits(10000));
|
||||
assertEquals(5, csb.countsetBits(31));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user