Added more unit tests

This commit is contained in:
2022-12-06 00:51:12 -05:00
parent 703b79c002
commit 5bdb9f8110
11 changed files with 620 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
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 static org.junit.jupiter.api.Assumptions.assumeTrue;
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 TestProblem24 extends BaseTest{
@InjectMocks
private Problem24 problem;
@Test
@Override
public void testDescription(){
assertEquals("What is the millionth lexicographic permutation of the digits 0123456789?", problem.getDescription());
assertFalse(problem.getSolved());
}
@Test
@Override
public void testSolve(){
assumeTrue(Boolean.valueOf(System.getProperty("longTests")));
assertThrows(Unsolved.class, () -> { problem.getPermutationsList(); });
assertThrows(Unsolved.class, () -> { problem.getPermutation(); });
problem.solve();
//Verify result
assertEquals(3628800, problem.getPermutationsList().size());
assertEquals("2783915460", problem.getPermutation());
assertEquals("The 1 millionth permutation is 2783915460", 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(){
assumeTrue(Boolean.valueOf(System.getProperty("longTests")));
problem.reset();
//Verify solved was reset
assertFalse(problem.getSolved());
super.testReset();
//Verify the problem can be solved again
testSolve();
}
}