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 TestProblem20 extends BaseTest{
@InjectMocks
private Problem20 problem;
@Test
@Override
public void testDescription(){
assertEquals("What is the sum of the digits of 100!?", problem.getDescription());
assertFalse(problem.getSolved());
}
@Test
@Override
public void testSolve(){
assertThrows(Unsolved.class, () -> { problem.getNumber(); });
assertThrows(Unsolved.class, () -> { problem.getNumberString(); });
assertThrows(Unsolved.class, () -> { problem.getSum(); });
problem.solve();
//Verify result
assertEquals(648, problem.getSum());
assertEquals(String.format("100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000%nThe sum of the digits is: 648"), 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();
}
}