Skip to content

[REFACTOR] [Hacker Rank]: Project Euler #1: Multiples of 3 and 5. Loa… #234

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 2 commits 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
4 changes: 4 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ jobs:
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
env:
ACTIONS_RUNTIME_TOKEN: ${{ secrets.GITHUB_TOKEN }}

report:
name: "Trivy (report)"
Expand All @@ -211,3 +213,5 @@ jobs:
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'table'
env:
ACTIONS_RUNTIME_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,48 @@

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 Euler001Test {

public static class Euler001TestCase {
public Integer a;
public Integer b;
public Integer n;
public Long expected;
}

private List<Euler001TestCase> testCases;

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

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

@Test void euler001() {

for (Euler001TestCase test : testCases) {
Long solutionFound = Euler001.euler001(test.a, test.b, test.n);

@ParameterizedTest
@CsvSource({
"3, 5, 10, 23, Test Case 1",
"3, 5, 100, 2318, Test Case 2",
"3, 5, 1000, 233168, Test Case 3"
})
void euler001(
int a,
int b,
int n,
long answer,
String testCase) {

Long solutionFound = Euler001.euler001(a, b, n);

String log = String.format("Problem 001 solved: %s. Answer must be %s",
testCase,
answer);

assertEquals(answer, solutionFound, log);
assertEquals(test.expected, solutionFound,
"%s(%d, %d, %d) => must be: %s".formatted(
"Euler001.euler001",
test.a, test.b, test.n,
test.expected
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{ "a": 3, "b": 5, "n": 10, "expected": 23 },
{ "a": 5, "b": 3, "n": 10, "expected": 23 },
{ "a": 3, "b": 5, "n": 100, "expected": 2318 },
{ "a": 3, "b": 5, "n": 1000, "expected": 233168 }
]