mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-06 17:13:58 -05:00
Added more unit tests
This commit is contained in:
@@ -112,8 +112,7 @@ public class Problem30 extends Problem{
|
||||
return String.format("The sum of all the numbers that can be written as the sum of the fifth powers of their digits is %d", sum);
|
||||
}
|
||||
//This returns the top number to be checked
|
||||
public long getTopNum(){
|
||||
solvedCheck("largest number checked");
|
||||
public static long getTopNum(){
|
||||
return TOP_NUM;
|
||||
}
|
||||
//This returns a copy of the vector holding all the numbers that are the sum of the fifth power of their digits
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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 TestProblem22 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem22 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("What is the total of all the name scores in this file?", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getNameScoreSum(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(871198282L, problem.getNameScoreSum());
|
||||
assertEquals("The answer to the question is 871198282", 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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 TestProblem23 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem23 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assumeTrue(Boolean.valueOf(System.getProperty("longTests")));
|
||||
assertThrows(Unsolved.class, () -> { problem.getSum(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(4179871, problem.getSum());
|
||||
assertEquals("The answer is 4179871", 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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
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.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 TestProblem25 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem25 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("What is the index of the first term in the Fibonacci sequence to contain 1000 digits?", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getNumber(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getNumberString(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getIndex(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getIndexString(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getIndexInt(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816"), problem.getNumber());
|
||||
assertEquals("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816", problem.getNumberString());
|
||||
assertEquals(BigInteger.valueOf(4782), problem.getIndex());
|
||||
assertEquals("4782", problem.getIndexString());
|
||||
assertEquals(4782, problem.getIndexInt());
|
||||
assertEquals(String.format("The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816%nIts index is 4782"), 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();
|
||||
}
|
||||
}
|
||||
@@ -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 TestProblem26 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem26 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("Find the value of d <= 999 for which 1/d contains the longest recurring cycle in its decimal fraction part.", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getLongestCycle(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getLongestNumber(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(982, problem.getLongestCycle());
|
||||
assertEquals(983, problem.getLongestNumber());
|
||||
assertEquals(String.format("The longest cycle is 982 digits long%nIt started with the number 983"), 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
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 TestProblem27 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem27 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("Find the product of the coefficients, |a| <= 999 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopA(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopB(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getTopN(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getProduct(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(-61, problem.getTopA());
|
||||
assertEquals(971, problem.getTopB());
|
||||
assertEquals(70, problem.getTopN());
|
||||
assertEquals(-59231, problem.getProduct());
|
||||
assertEquals(String.format("The greatest number of primes found is 70%nIt was found with A = -61, B = 971%nThe product of A and B is -59231"), 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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.assertNotNull;
|
||||
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 TestProblem28 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem28 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getGrid(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getSum(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertNotNull(problem.getGrid());
|
||||
assertEquals(669171001, problem.getSum());
|
||||
assertEquals("The sum of the diagonals in the given grid is 669171001", 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();
|
||||
}
|
||||
}
|
||||
@@ -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 TestProblem29 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem29 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getUnique(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getNumUnique(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(9183, problem.getUnique().size());
|
||||
assertEquals(9183, problem.getNumUnique());
|
||||
assertEquals("The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183", 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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 TestProblem30 extends BaseTest{
|
||||
@InjectMocks
|
||||
private Problem30 problem;
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testDescription(){
|
||||
assertEquals("Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.", problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSolve(){
|
||||
assertThrows(Unsolved.class, () -> { problem.getListOfSumOfFifths(); });
|
||||
assertThrows(Unsolved.class, () -> { problem.getSumOfList(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify result
|
||||
assertEquals(List.of(4150L, 4151L, 54748L, 92727L, 93084L, 194979L), problem.getListOfSumOfFifths());
|
||||
assertEquals(443839L, problem.getSumOfList());
|
||||
assertEquals(String.format("The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839"), 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user