mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Create package prime, matrix and games (#6139)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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}}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user