|
@ -0,0 +1,61 @@ |
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
public class CalculationsTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testCalculateSquare() { |
|
|
|
|
|
Calculations calc = new Calculations(); |
|
|
|
|
|
|
|
|
|
|
|
// Test with a positive number |
|
|
|
|
|
assertEquals(25, calc.calculateSquare(5)); |
|
|
|
|
|
|
|
|
|
|
|
// Test with a negative number |
|
|
|
|
|
assertEquals(16, calc.calculateSquare(-4)); |
|
|
|
|
|
|
|
|
|
|
|
// Test with zero |
|
|
|
|
|
assertEquals(0, calc.calculateSquare(0)); |
|
|
|
|
|
|
|
|
|
|
|
// Test with a large number |
|
|
|
|
|
assertEquals(1000000, calc.calculateSquare(1000)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testCalculateFactorial() { |
|
|
|
|
|
Calculations fact = new Calculations(); |
|
|
|
|
|
|
|
|
|
|
|
// Test with positive numbers |
|
|
|
|
|
assertEquals(1, fact.calculateFactorial(0)); |
|
|
|
|
|
assertEquals(1, fact.calculateFactorial(1)); |
|
|
|
|
|
assertEquals(2, fact.calculateFactorial(2)); |
|
|
|
|
|
assertEquals(6, fact.calculateFactorial(3)); |
|
|
|
|
|
assertEquals(24, fact.calculateFactorial(4)); |
|
|
|
|
|
assertEquals(120, fact.calculateFactorial(5)); |
|
|
|
|
|
|
|
|
|
|
|
// Test with large number |
|
|
|
|
|
assertEquals(3628800, fact.calculateFactorial(10)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
|
|
public void testNegativeNumber() { |
|
|
|
|
|
Calculations fact = new Calculations(); |
|
|
|
|
|
fact.calculateFactorial(-5); // Should throw IllegalArgumentException |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void testIsPrime() { |
|
|
|
|
|
// Prime |
|
|
|
|
|
int[] primeNumbers = {2, 3, 5, 7, 11, 13}; |
|
|
|
|
|
int[] nonPrimeNumbers = {22, 33, 25, 4, 8, 14}; |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < primeNumbers.length; i++) { |
|
|
|
|
|
assertTrue(Calculations.isPrime(primeNumbers[i])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < nonPrimeNumbers.length; i++) { |
|
|
|
|
|
assertFalse(Calculations.isPrime(nonPrimeNumbers[i])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|