Skip to content

[REFACTOR] [Hacker Rank]: Project Euler #2: Even Fibonacci numbers. L… #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,47 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import util.JsonLoader;


@TestInstance(Lifecycle.PER_CLASS)
class Euler002Test {

@ParameterizedTest
@CsvSource({
"10, 10, Sample Test case 0 -> 1",
"100, 44, Sample Test case 0 -> 2",
})
void euler001(
int n,
long answer,
String testCase) {
public static class Euler002TestCase {
public Integer n;
public Long expected;
}

private List<Euler002TestCase> testCases;

@BeforeAll
public void setup() throws IOException {
String path = String.join("/",
"hackerrank",
"projecteuler",
"euler002.testcases.json");

this.testCases = JsonLoader.loadJson(path, Euler002TestCase.class);
}

@Test void euler002() {

Long solutionFound = Euler002.euler002(n);
for (Euler002TestCase test : testCases) {
Long solutionFound = Euler002.euler002(test.n);

String log = String.format("Problem 002 %s answer must be: %d", testCase, answer);
assertEquals(answer, solutionFound, log);
assertEquals(test.expected, solutionFound,
"%s(%d) => must be: %s".formatted(
"Euler002.euler002",
test.n,
test.expected
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "n": 10, "expected": 10 },
{ "n": 100, "expected": 44 }
]