Files
ProjectEulerJava/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java
2022-12-06 00:51:12 -05:00

63 lines
1.7 KiB
Java

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 java.util.List;
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 TestProblem21 extends BaseTest{
@InjectMocks
private Problem21 problem;
@Test
@Override
public void testDescription(){
assertEquals("Evaluate the sum of all the amicable numbers under 10000", problem.getDescription());
assertFalse(problem.getSolved());
}
@Test
@Override
public void testSolve(){
assertThrows(Unsolved.class, () -> { problem.getAmicable(); });
assertThrows(Unsolved.class, () -> { problem.getSum(); });
problem.solve();
//Verify result
assertEquals(List.of(220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368), problem.getAmicable());
assertEquals(31626, problem.getSum());
assertEquals(String.format("All amicable numbers less than 10000 are%n220%n284%n1184%n1210%n2620%n2924%n5020%n5564%n6232%n6368%nThe sum of all of these amicable numbers is 31626"), 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();
}
}