refactor: change packages (#5430)

* refactor: change package

* refactor: fix name

---------

Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
Alex Klymenko
2024-08-30 11:58:24 +02:00
committed by GitHub
parent f8ff6af893
commit b0de93b3ce
10 changed files with 13 additions and 13 deletions

View File

@ -0,0 +1,33 @@
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class EulersFunctionTest {
@ParameterizedTest
@MethodSource("provideNumbersForGetEuler")
void testGetEuler(int input, int expected) {
assertEquals(expected, EulersFunction.getEuler(input));
}
@ParameterizedTest
@MethodSource("provideInvalidNumbersForGetEuler")
void testGetEulerThrowsExceptionForNonPositiveInput(int input) {
assertThrows(IllegalArgumentException.class, () -> EulersFunction.getEuler(input));
}
private static Stream<Arguments> provideNumbersForGetEuler() {
return Stream.of(Arguments.of(1, 1), Arguments.of(2, 1), Arguments.of(3, 2), Arguments.of(4, 2), Arguments.of(5, 4), Arguments.of(6, 2), Arguments.of(10, 4), Arguments.of(21, 12), Arguments.of(69, 44), Arguments.of(47, 46), Arguments.of(46, 22), Arguments.of(55, 40), Arguments.of(34, 16),
Arguments.of(20, 8), Arguments.of(1024, 512));
}
private static Stream<Arguments> provideInvalidNumbersForGetEuler() {
return Stream.of(Arguments.of(0), Arguments.of(-1), Arguments.of(-10));
}
}

View File

@ -0,0 +1,46 @@
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class SieveOfEratosthenesTest {
@Test
public void testfFindPrimesTill1() {
assertArrayEquals(new int[] {}, SieveOfEratosthenes.findPrimesTill(1));
}
@Test
public void testfFindPrimesTill2() {
assertArrayEquals(new int[] {2}, SieveOfEratosthenes.findPrimesTill(2));
}
@Test
public void testfFindPrimesTill4() {
var primesTill4 = new int[] {2, 3};
assertArrayEquals(primesTill4, SieveOfEratosthenes.findPrimesTill(3));
assertArrayEquals(primesTill4, SieveOfEratosthenes.findPrimesTill(4));
}
@Test
public void testfFindPrimesTill40() {
var primesTill40 = new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
assertArrayEquals(primesTill40, SieveOfEratosthenes.findPrimesTill(37));
assertArrayEquals(primesTill40, SieveOfEratosthenes.findPrimesTill(38));
assertArrayEquals(primesTill40, SieveOfEratosthenes.findPrimesTill(39));
assertArrayEquals(primesTill40, SieveOfEratosthenes.findPrimesTill(40));
}
@Test
public void testfFindPrimesTill240() {
var primesTill240 = new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239};
assertArrayEquals(primesTill240, SieveOfEratosthenes.findPrimesTill(239));
assertArrayEquals(primesTill240, SieveOfEratosthenes.findPrimesTill(240));
}
@Test
public void testFindPrimesTillThrowsExceptionForNonPositiveInput() {
assertThrows(IllegalArgumentException.class, () -> SieveOfEratosthenes.findPrimesTill(0));
}
}