Added more unit tests

This commit is contained in:
2022-12-05 23:50:14 -05:00
parent 7a3f2214f8
commit 703b79c002
11 changed files with 594 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
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 TestProblem14 extends BaseTest{
@InjectMocks
private Problem14 problem;
@Test
@Override
public void testDescription(){
assertEquals("Which starting number, under 1000000, produces the longest chain using the iterative sequence?", problem.getDescription());
assertFalse(problem.getSolved());
}
@Test
@Override
public void testSolve(){
assertThrows(Unsolved.class, () -> { problem.getLength(); });
assertThrows(Unsolved.class, () -> { problem.getStartingNumber(); });
problem.solve();
//Verify result
assertEquals(525, problem.getLength());
assertEquals(837799, problem.getStartingNumber());
assertEquals("The number 837799 produced a chain of 525 steps", problem.getResult());
//Verify the porblem variables and functions were called
verifyProblem(problem);
//Verify the porblem 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();
}
}