Create package prime, matrix and games (#6139)

This commit is contained in:
varada610
2025-01-27 03:10:41 -08:00
committed by GitHub
parent f9efd382d1
commit 4ef06822ca
27 changed files with 123 additions and 160 deletions

View File

@@ -3,6 +3,7 @@ package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.thealgorithms.maths.Prime.SquareFreeInteger;
import java.util.List;
import org.junit.jupiter.api.Test;

View File

@@ -1,8 +1,9 @@
package com.thealgorithms.maths;
package com.thealgorithms.maths.prime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.thealgorithms.maths.Prime.LiouvilleLambdaFunction;
import org.junit.jupiter.api.Test;
class LiouvilleLambdaFunctionTest {

View File

@@ -1,8 +1,9 @@
package com.thealgorithms.maths;
package com.thealgorithms.maths.prime;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.thealgorithms.maths.Prime.MillerRabinPrimalityCheck;
import org.junit.jupiter.api.Test;
class MillerRabinPrimalityCheckTest {

View File

@@ -1,8 +1,9 @@
package com.thealgorithms.maths;
package com.thealgorithms.maths.prime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.thealgorithms.maths.Prime.MobiusFunction;
import org.junit.jupiter.api.Test;
class MobiusFunctionTest {

View File

@@ -1,5 +1,6 @@
package com.thealgorithms.maths;
package com.thealgorithms.maths.prime;
import com.thealgorithms.maths.Prime.PrimeCheck;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@@ -1,7 +1,8 @@
package com.thealgorithms.maths;
package com.thealgorithms.maths.prime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.thealgorithms.maths.Prime.PrimeFactorization;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;

View File

@@ -1,4 +1,4 @@
package com.thealgorithms.maths;
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

View File

@@ -1,7 +1,8 @@
package com.thealgorithms.maths;
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.thealgorithms.matrix.utils.MatrixUtil;
import java.math.BigDecimal;
import java.util.Objects;
import org.junit.jupiter.api.Test;

View File

@@ -1,7 +1,7 @@
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
@@ -10,44 +10,44 @@ class MirrorOfMatrixTest {
@Test
void testMirrorMatrixRegularMatrix() {
int[][] originalMatrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int[][] expectedMirrorMatrix = {{3, 2, 1}, {6, 5, 4}, {9, 8, 7}};
int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
double[][] originalMatrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
double[][] expectedMirrorMatrix = {{3, 2, 1}, {6, 5, 4}, {9, 8, 7}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixEmptyMatrix() {
int[][] originalMatrix = {};
int[][] expectedMirrorMatrix = {};
int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
double[][] originalMatrix = {};
Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
assertEquals("The input matrix cannot be empty", e.getMessage());
}
@Test
void testMirrorMatrixSingleElementMatrix() {
int[][] originalMatrix = {{42}};
int[][] expectedMirrorMatrix = {{42}};
int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
double[][] originalMatrix = {{42}};
double[][] expectedMirrorMatrix = {{42}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixMultipleRowsOneColumnMatrix() {
int[][] originalMatrix = {{1}, {2}, {3}, {4}};
int[][] expectedMirrorMatrix = {{1}, {2}, {3}, {4}};
int[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
double[][] originalMatrix = {{1}, {2}, {3}, {4}};
double[][] expectedMirrorMatrix = {{1}, {2}, {3}, {4}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixNullInput() {
int[][] originalMatrix = null;
assertNull(MirrorOfMatrix.mirrorMatrix(originalMatrix));
double[][] originalMatrix = null;
Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
assertEquals("The input matrix cannot be null", e.getMessage());
}
@Test
void testMirrotMarixThrows() {
assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(new int[][] {{1}, {2, 3}}));
void testMirrorMatrixThrows() {
assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(new double[][] {{1}, {2, 3}}));
}
}

View File

@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.puzzlesandgames;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

View File

@@ -1,4 +1,4 @@
package com.thealgorithms.others;
package com.thealgorithms.puzzlesandgames;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

View File

@@ -1,4 +1,4 @@
package com.thealgorithms.misc;
package com.thealgorithms.puzzlesandgames;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;