mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-07 01:23:56 -05:00
Changed test methods
This commit is contained in:
@@ -2,59 +2,53 @@ 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.math.BigInteger;
|
||||
|
||||
import org.junit.jupiter.api.Order;
|
||||
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;
|
||||
static{
|
||||
description = "What is the sum of the digits of 100!?";
|
||||
result = String.format("100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000%nThe sum of the digits is: 648");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("What is the sum of the digits of 100!?", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
super.testDescription(problem);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getNumber(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getNumberString(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getSum(); });
|
||||
|
||||
problem.solve();
|
||||
super.testSolve(problem);
|
||||
|
||||
//Verify result
|
||||
assertEquals(new BigInteger("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"), problem.getNumber());
|
||||
assertEquals("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000", problem.getNumberString());
|
||||
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
|
||||
@Order(3)
|
||||
@Override
|
||||
public void testReset(){
|
||||
problem.reset();
|
||||
|
||||
//Verify solved was reset
|
||||
assertFalse(problem.getSolved());
|
||||
super.testReset();
|
||||
|
||||
//Verify the problem can be solved again
|
||||
testSolve();
|
||||
super.testReset(problem);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user