|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 |
|
5 |
| -import org.junit.jupiter.params.ParameterizedTest; |
6 |
| -import org.junit.jupiter.params.provider.CsvSource; |
| 5 | +import java.io.IOException; |
| 6 | +import java.util.List; |
| 7 | +import org.junit.jupiter.api.BeforeAll; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.api.TestInstance; |
| 10 | +import org.junit.jupiter.api.TestInstance.Lifecycle; |
| 11 | +import util.JsonLoader; |
7 | 12 |
|
8 | 13 |
|
| 14 | +@TestInstance(Lifecycle.PER_CLASS) |
9 | 15 | class Euler002Test {
|
10 | 16 |
|
11 |
| - @ParameterizedTest |
12 |
| - @CsvSource({ |
13 |
| - "10, 10, Sample Test case 0 -> 1", |
14 |
| - "100, 44, Sample Test case 0 -> 2", |
15 |
| - }) |
16 |
| - void euler001( |
17 |
| - int n, |
18 |
| - long answer, |
19 |
| - String testCase) { |
| 17 | + public static class Euler002TestCase { |
| 18 | + public Integer n; |
| 19 | + public Long expected; |
| 20 | + } |
| 21 | + |
| 22 | + private List<Euler002TestCase> testCases; |
| 23 | + |
| 24 | + @BeforeAll |
| 25 | + public void setup() throws IOException { |
| 26 | + String path = String.join("/", |
| 27 | + "hackerrank", |
| 28 | + "projecteuler", |
| 29 | + "euler002.testcases.json"); |
| 30 | + |
| 31 | + this.testCases = JsonLoader.loadJson(path, Euler002TestCase.class); |
| 32 | + } |
| 33 | + |
| 34 | + @Test void euler002() { |
20 | 35 |
|
21 |
| - Long solutionFound = Euler002.euler002(n); |
| 36 | + for (Euler002TestCase test : testCases) { |
| 37 | + Long solutionFound = Euler002.euler002(test.n); |
22 | 38 |
|
23 |
| - String log = String.format("Problem 002 %s answer must be: %d", testCase, answer); |
24 |
| - assertEquals(answer, solutionFound, log); |
| 39 | + assertEquals(test.expected, solutionFound, |
| 40 | + "%s(%d) => must be: %s".formatted( |
| 41 | + "Euler002.euler002", |
| 42 | + test.n, |
| 43 | + test.expected |
| 44 | + ) |
| 45 | + ); |
| 46 | + } |
25 | 47 | }
|
26 | 48 | }
|
0 commit comments