mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Added more unit tests
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package com.mattrixwv.project_euler.problems;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.mattrixwv.project_euler.exceptions.Unsolved;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TestProblem27 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem27 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("Find the product of the coefficients, |a| <= 999 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopA(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopB(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopN(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getProduct(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(-61, problem.getTopA());
|
||||
assertEquals(971, problem.getTopB());
|
||||
assertEquals(70, problem.getTopN());
|
||||
assertEquals(-59231, problem.getProduct());
|
||||
assertEquals(String.format("The greatest number of primes found is 70%nIt was found with A = -61, B = 971%nThe product of A and B is -59231"), problem.getResult());
|
||||
//Verify the problem variables and functions were called
|
||||
verifyProblem(problem);
|
||||
|
||||
//Verify the problem won't be run again
|
||||
verifyProblemSecondRun(problem);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testReset(){
|
||||
problem.reset();
|
||||
|
||||
//Verify solved was reset
|
||||
assertFalse(problem.getSolved());
|
||||
super.testReset();
|
||||
|
||||
//Verify the problem can be solved again
|
||||
testSolve();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user