diff --git a/src/test/java/com/mattrixwv/project_euler/problems/BaseTest.java b/src/test/java/com/mattrixwv/project_euler/problems/BaseTest.java index 47401e0..4b826dc 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/BaseTest.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/BaseTest.java @@ -1,31 +1,57 @@ 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.Assertions.assertTrue; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atMostOnce; import static org.mockito.Mockito.verify; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; import com.mattrixwv.Stopwatch; +import com.mattrixwv.project_euler.exceptions.Unsolved; + +@ExtendWith(MockitoExtension.class) +@TestInstance(Lifecycle.PER_CLASS) +@TestMethodOrder(OrderAnnotation.class) public abstract class BaseTest{ @Spy protected Stopwatch timer; + protected static String description; + protected static String result; public abstract void testDescription(); + public void testDescription(Problem problem){ + assertEquals(description, problem.getDescription()); + assertFalse(problem.getSolved()); + } public abstract void testSolve(); - protected void verifyProblem(Problem problem){ + public void testSolve(Problem problem){ + //Verify the results cannot be seen until the problem has been run + assertThrows(Unsolved.class, () -> { problem.getResult(); }); + + problem.solve(); + //Verify solved was set assertTrue(problem.getSolved()); + assertEquals(result, problem.getResult()); //Verify timer function were called verify(timer, atLeastOnce()).start(); verify(timer, atLeastOnce()).stop(); - } - protected void verifyProblemSecondRun(Problem problem){ + //Verify the problem won't be run again problem.solve(); //Verify solved is still set @@ -35,8 +61,16 @@ public abstract class BaseTest{ verify(timer, atMostOnce()).stop(); } - public void testReset(){ - //Verify timer was reset - verify(timer, atLeastOnce()).reset(); + public abstract void testReset(); + public void testReset(Problem problem){ + assertTrue(problem.solved); + + problem.reset(); + + //Verify solved was reset + assertFalse(problem.getSolved()); + + //Verify the problem can be solved again + testSolve(); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java index 3a606f4..638ad0a 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java @@ -2,56 +2,48 @@ 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.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 TestProblem1 extends BaseTest{ @InjectMocks private Problem1 problem = new Problem1(); + static{ + description = "What is the sum of all the multiples of 3 or 5 that are less than 1000?"; + result = "The sum of all numbers < 1000 is 233168"; + } + @Test + @Order(1) + @Override public void testDescription(){ - assertEquals("What is the sum of all the multiples of 3 or 5 that are less than 1000?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(233168, problem.getSum()); - assertEquals("The sum of all numbers < 1000 is 233168", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java index 3a1c9c4..aa45ea4 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java @@ -2,57 +2,47 @@ 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.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 TestProblem10 extends BaseTest{ @InjectMocks private Problem10 problem; + static{ + description = "Find the sum of all the primes below 2000000."; + result = "The sum of all the primes < 2000000 is 142913828922"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Find the sum of all the primes below 2000000.", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(142913828922L, problem.getSum()); - assertEquals("The sum of all the primes < 2000000 is 142913828922", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java index 8f98a03..8ceb2e7 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java @@ -2,61 +2,51 @@ 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.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 TestProblem11 extends BaseTest{ @InjectMocks private Problem11 problem; + static{ + description = "What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?"; + result = String.format("The greatest product of 4 numbers in a line is 70600674%nThe numbers are [89, 94, 97, 87]"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumbers(); }); assertThrows(Unsolved.class, () -> { problem.getProduct(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(List.of(89, 94, 97, 87), problem.getNumbers()); assertEquals(70600674, problem.getProduct()); - assertEquals(String.format("The greatest product of 4 numbers in a line is 70600674%nThe numbers are [89, 94, 97, 87]"), 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java index 6461379..793f3cb 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java @@ -2,31 +2,33 @@ 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.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 TestProblem12 extends BaseTest{ @InjectMocks private Problem12 problem; + static{ + description = "What is the value of the first triangle number to have over 500 divisors?"; + result = "The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the value of the first triangle number to have over 500 divisors?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTriangularNumber(); }); @@ -34,31 +36,19 @@ public class TestProblem12 extends BaseTest{ assertThrows(Unsolved.class, () -> { problem.getDivisorsOfTriangularNumber(); }); assertThrows(Unsolved.class, () -> { problem.getNumberOfDivisors(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(76576500, problem.getTriangularNumber()); assertEquals(12375, problem.getLastNumberAdded()); assertEquals(576, problem.getDivisorsOfTriangularNumber().size()); assertEquals(576, problem.getNumberOfDivisors()); - assertEquals("The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors", 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 porblem can be solved again - testSolve(); + super.testReset(problem); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java index 3a90ccc..32858a4 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java @@ -1,32 +1,36 @@ 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 TestProblem13 extends BaseTest{ @InjectMocks private Problem13 problem; + static{ + description = "Work out the first ten digits of the sum of the one-hundred 50-digit numbers"; + result = String.format("The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672%nThe first 10 digits of the sum of the numbers is 5537376230"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Work out the first ten digits of the sum of the one-hundred 50-digit numbers", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumbers(); }); @@ -37,24 +41,12 @@ public class TestProblem13 extends BaseTest{ //Verify result assertEquals(100, problem.getNumbers().size()); assertEquals(new BigInteger("5537376230390876637302048746832985971773659831892672"), problem.getSum()); - assertEquals(String.format("The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672%nThe first 10 digits of the sum of the numbers is 5537376230"), 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java index 17d1032..fcf1261 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java @@ -2,59 +2,49 @@ 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.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 TestProblem14 extends BaseTest{ @InjectMocks private Problem14 problem; + static{ + description = "Which starting number, under 1000000, produces the longest chain using the iterative sequence?"; + result = "The number 837799 produced a chain of 525 steps"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Which starting number, under 1000000, produces the longest chain using the iterative sequence?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLength(); }); assertThrows(Unsolved.class, () -> { problem.getStartingNumber(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(525, problem.getLength()); assertEquals(837799, problem.getStartingNumber()); - assertEquals("The number 837799 produced a chain of 525 steps", problem.getResult()); - //Verify the porblem variables and functions were called - verifyProblem(problem); - - //Verify the porblem 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java index ecebeb3..4267d45 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java @@ -2,58 +2,48 @@ 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.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 TestProblem15 extends BaseTest{ @InjectMocks private Problem15Override problem; + static{ + description = "How many routes from the top left corner to the bottom right corner are there through a 5x5 grid if you can only move right and down?"; + result = "The number of routes is 252"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("How many routes from the top left corner to the bottom right corner are there through a 5x5 grid if you can only move right and down?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumberOfRoutes(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(252, problem.getNumberOfRoutes()); - assertEquals("The number of routes is 252", 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); } public static class Problem15Override extends Problem15{ diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java index 2259ad1..afb28c9 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java @@ -1,56 +1,48 @@ 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.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 TestProblem16 extends BaseTest{ @InjectMocks private Problem16 problem; + static{ + description = "What is the sum of the digits of the number 2^1000?"; + result = String.format("2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376%nThe sum of the elements is 1366"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the sum of the digits of the number 2^1000?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(1366, problem.getSum()); - assertEquals(String.format("2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376%nThe sum of the elements is 1366"), 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java index b86036e..0c3b8c1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java @@ -1,56 +1,48 @@ 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.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 TestProblem17 extends BaseTest{ @InjectMocks private Problem17 problem; + static{ + description = "If all the numbers from 1 to 1000 inclusive were written out in words, how many letters would be used?"; + result = "The sum of all the letters in all the numbers 1-1000 is 21124"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("If all the numbers from 1 to 1000 inclusive were written out in words, how many letters would be used?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLetterCount(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(21124, problem.getLetterCount()); - assertEquals("The sum of all the letters in all the numbers 1-1000 is 21124", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java index fe504a9..4e8e8eb 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java @@ -1,56 +1,48 @@ 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.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 TestProblem18 extends BaseTest{ @InjectMocks private Problem18 problem; + static{ + description = "Find the maximum total from top to bottom"; + result = "The value of the longest path is 1074"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Find the maximum total from top to bottom", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTotal(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(1074, problem.getTotal()); - assertEquals("The value of the longest path is 1074", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java index 49c191f..d527a74 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java @@ -2,57 +2,47 @@ 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.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 TestProblem19 extends BaseTest{ @InjectMocks private Problem19 problem; + static{ + description = "How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?"; + result = "There are 171 Sundays that landed on the first of the months from 1901 to 2000"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTotalSundays(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(171, problem.getTotalSundays()); - assertEquals("There are 171 Sundays that landed on the first of the months from 1901 to 2000", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java index beb9047..52de66c 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java @@ -2,58 +2,48 @@ 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.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 TestProblem2 extends BaseTest{ @InjectMocks private Problem2 problem; + static{ + description = "What is the sum of the even Fibonacci numbers less than 4000000?"; + result = "The sum of all even fibonacci numbers <= 3999999 is 4613732"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the sum of the even Fibonacci numbers less than 4000000?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(4613732, problem.getSum()); - assertEquals("The sum of all even fibonacci numbers <= 3999999 is 4613732", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java index 511eb23..377172a 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java @@ -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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java index 2f693d6..8906070 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java @@ -2,61 +2,51 @@ 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.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 TestProblem21 extends BaseTest{ @InjectMocks private Problem21 problem; + static{ + description = "Evaluate the sum of all the amicable numbers under 10000"; + result = 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"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Evaluate the sum of all the amicable numbers under 10000", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getAmicable(); }); assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java index ea348b4..4c798b9 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java @@ -2,57 +2,47 @@ 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.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 TestProblem22 extends BaseTest{ @InjectMocks private Problem22 problem; + static{ + description = "What is the total of all the name scores in this file?"; + result = "The answer to the question is 871198282"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the total of all the name scores in this file?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNameScoreSum(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java index 429aeea..30a5965 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java @@ -2,58 +2,48 @@ 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.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 TestProblem23 extends BaseTest{ @InjectMocks private Problem23Override problem; + static{ + description = "Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers"; + result = "The answer is 2035227"; + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(2035227, problem.getSum()); - assertEquals("The answer is 2035227", 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); } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java index d4c0965..aa5978e 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java @@ -2,60 +2,50 @@ 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.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 TestProblem24 extends BaseTest{ @InjectMocks private Problem24Override problem; + static{ + description = "What is the 100th lexicographic permutation of the digits 01234?"; + result = "The 100th permutation is 40231"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the 100th lexicographic permutation of the digits 01234?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPermutationsList(); }); assertThrows(Unsolved.class, () -> { problem.getPermutation(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(120, problem.getPermutationsList().size()); assertEquals("40231", problem.getPermutation()); - assertEquals("The 100th permutation is 40231", 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); } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java index f5265ba..435a142 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java @@ -2,33 +2,35 @@ 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 TestProblem25 extends BaseTest{ @InjectMocks private Problem25 problem; + static{ + description = "What is the index of the first term in the Fibonacci sequence to contain 1000 digits?"; + result = String.format("The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816%nIts index is 4782"); + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumber(); }); @@ -37,7 +39,7 @@ public class TestProblem25 extends BaseTest{ assertThrows(Unsolved.class, () -> { problem.getIndexString(); }); assertThrows(Unsolved.class, () -> { problem.getIndexInt(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816"), problem.getNumber()); @@ -45,24 +47,12 @@ public class TestProblem25 extends BaseTest{ 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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java index 1c855a5..481cec1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java @@ -2,59 +2,49 @@ 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.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 TestProblem26 extends BaseTest{ @InjectMocks private Problem26 problem; + static{ + description = "Find the value of d <= 999 for which 1/d contains the longest recurring cycle in its decimal fraction part."; + result = String.format("The longest cycle is 982 digits long%nIt started with the number 983"); + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLongestCycle(); }); assertThrows(Unsolved.class, () -> { problem.getLongestNumber(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java index c7a5ade..7204ab0 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java @@ -2,31 +2,33 @@ 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.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 TestProblem27 extends BaseTest{ @InjectMocks private Problem27 problem; + static{ + description = "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"; + result = 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"); + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTopA(); }); @@ -34,31 +36,19 @@ public class TestProblem27 extends BaseTest{ assertThrows(Unsolved.class, () -> { problem.getTopN(); }); assertThrows(Unsolved.class, () -> { problem.getProduct(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java index e088056..70f9602 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java @@ -2,60 +2,50 @@ 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.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 TestProblem28 extends BaseTest{ @InjectMocks private Problem28 problem; + static{ + description = "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?"; + result = "The sum of the diagonals in the given grid is 669171001"; + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getGrid(); }); assertThrows(Unsolved.class, () -> { problem.getSum(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java index 9501c7a..a561279 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java @@ -2,59 +2,49 @@ 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.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 TestProblem29 extends BaseTest{ @InjectMocks private Problem29 problem; + static{ + description = "How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?"; + result = "The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183"; + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getUnique(); }); assertThrows(Unsolved.class, () -> { problem.getNumUnique(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java index 3b42745..0556897 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java @@ -2,62 +2,52 @@ 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.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.NumberAlgorithms; import com.mattrixwv.project_euler.exceptions.Unsolved; -@ExtendWith(MockitoExtension.class) public class TestProblem3 extends BaseTest{ @InjectMocks private Problem3 problem; + static{ + description = "What is the largest prime factor of 600851475143?"; + result = "The largest factor of the number 600851475143 is 6857"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the largest prime factor of 600851475143?", problem.getDescription()); + super.testDescription(problem); assertEquals(600851475143L, Problem3.getGoalNumber()); - assertFalse(problem.getSolved()); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); assertThrows(Unsolved.class, () -> { problem.getFactors(); }); assertThrows(Unsolved.class, () -> { problem.getLargestFactor(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(NumberAlgorithms.getFactors(600851475143L), problem.getFactors()); assertEquals(6857, problem.getLargestFactor()); - assertEquals("The largest factor of the number 600851475143 is 6857", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java index 5e0d7b8..7df22a0 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java @@ -2,61 +2,51 @@ 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.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 TestProblem30 extends BaseTest{ @InjectMocks private Problem30 problem; + static{ + description = "Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits."; + result = String.format("The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839"); + } @Test + @Order(1) @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()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getListOfSumOfFifths(); }); assertThrows(Unsolved.class, () -> { problem.getSumOfList(); }); - problem.solve(); + super.testSolve(problem); //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 + @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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java index c018139..a2bb916 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java @@ -2,59 +2,49 @@ 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.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 TestProblem4 extends BaseTest{ @InjectMocks private Problem4 problem; + static{ + description = "Find the largest palindrome made from the product of two 3-digit numbers"; + result = "The largest palindrome is 906609"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Find the largest palindrome made from the product of two 3-digit numbers", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPalindromes(); }); assertThrows(Unsolved.class, () -> { problem.getLargestPalindrome(); }); - problem.solve(); + super.testSolve(problem); //verify result assertEquals(1239, problem.getPalindromes().size()); assertEquals(906609, problem.getLargestPalindrome()); - assertEquals("The largest palindrome is 906609", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java index d262aea..7136317 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java @@ -2,57 +2,47 @@ 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.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 TestProblem5 extends BaseTest{ @InjectMocks private Problem5 problem; + static{ + description = "What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?"; + result = "The smallest positive number evenly divisible by all numbers 1-20 is 232792560"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumber(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(232792560, problem.getNumber()); - assertEquals("The smallest positive number evenly divisible by all numbers 1-20 is 232792560", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java index 234c5d6..454b88d 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java @@ -2,31 +2,33 @@ 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.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 TestProblem6 extends BaseTest{ @InjectMocks private Problem6 problem; + static{ + description = "Find the difference between the sum of the squares and the square of the sum of the numbers 1-100."; + result = "The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Find the difference between the sum of the squares and the square of the sum of the numbers 1-100.", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSumOfSquares(); }); @@ -39,24 +41,12 @@ public class TestProblem6 extends BaseTest{ assertEquals(338350, problem.getSumOfSquares()); assertEquals(25502500, problem.getSquareOfSum()); assertEquals(25164150, problem.getDifference()); - assertEquals("The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java index d78dd84..912755c 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java @@ -2,57 +2,47 @@ 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.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 TestProblem7 extends BaseTest{ @InjectMocks private Problem7 problem; + static{ + description = "What is the 10001th prime number?"; + result = "The 10001th prime number is 104743"; + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("What is the 10001th prime number?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPrime(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(104743, problem.getPrime()); - assertEquals("The 10001th prime number is 104743", 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java index 1f03aaa..47bcd81 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java @@ -2,59 +2,49 @@ 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.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 TestProblem8 extends BaseTest{ @InjectMocks private Problem8 problem; + static{ + description = "Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?"; + result = String.format("The greatest product is 23514624000%nThe numbers are 5576689664895"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLargestNums(); }); assertThrows(Unsolved.class, () -> { problem.getLargestProduct(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals("5576689664895", problem.getLargestNums()); assertEquals(23514624000L, problem.getLargestProduct()); - assertEquals(String.format("The greatest product is 23514624000%nThe numbers are 5576689664895"), problem.getResult()); - //Verify the problem variables and functions were called - verifyProblem(problem); - - //Verify the porblem 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); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java index d33f052..9d2e7c8 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java @@ -1,30 +1,34 @@ 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.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 TestProblem9 extends BaseTest{ @InjectMocks private Problem9 problem; + static{ + description = "There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc."; + result = String.format("The Pythagorean triplet is 200 + 375 + 425%nThe numbers' product is 31875000"); + } @Test + @Order(1) @Override public void testDescription(){ - assertEquals("There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.", problem.getDescription()); - assertFalse(problem.getSolved()); + super.testDescription(problem); } @Test + @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSideA(); }); @@ -32,31 +36,19 @@ public class TestProblem9 extends BaseTest{ assertThrows(Unsolved.class, () -> { problem.getSideC(); }); assertThrows(Unsolved.class, () -> { problem.getProduct(); }); - problem.solve(); + super.testSolve(problem); //Verify result assertEquals(200, problem.getSideA()); assertEquals(375, problem.getSideB()); assertEquals(425, problem.getSideC()); assertEquals(31875000, problem.getProduct()); - assertEquals(String.format("The Pythagorean triplet is 200 + 375 + 425%nThe numbers' product is 31875000"), 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); } }