Skip to content

Commit

Permalink
Added new GitHub Action workflow for dependency review, new coding ch…
Browse files Browse the repository at this point in the history
…allenge question created (partial)
  • Loading branch information
shortthirdman committed Sep 22, 2024
1 parent cf35351 commit 7a3207a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 3 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request,
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
# Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable
# packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on:
pull_request:
branches: [ 'main' ]

permissions:
contents: read
pull-requests: write
security-events: write

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout repository'
uses: actions/checkout@v4

- name: 'Dependency Review'
uses: actions/dependency-review-action@v4
with:
comment-summary-in-pr: always
fail-on-severity: moderate
vulnerability-check: true
deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later
retry-on-snapshot-warnings: true
show-openssf-scorecard: true
14 changes: 11 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
branches: [ "main" ]

jobs:
build:
maven-build:

runs-on: ubuntu-latest
permissions:
Expand All @@ -25,7 +25,9 @@ jobs:


steps:
- uses: actions/checkout@v4
- name: Checkout sources
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand All @@ -37,4 +39,10 @@ jobs:
run: mvn -B clean verify --file pom.xml

- name: Run Tests and Code-Coverage
run: mvn jacoco:prepare-agent clean test jacoco:report --file pom.xml
run: mvn jacoco:prepare-agent clean test jacoco:report --file pom.xml

- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@v4

# - name: Release source and test archives
# run: mvn -B clean verify --file pom.xml -Prelease
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
<encoding>${project.build.sourceEncoding}</encoding>
<reportFormat>brief</reportFormat>
<printSummary>true</printSummary>
<excludes>
<exclude>*com.shortthirdman.quickstart.common.*</exclude>
</excludes>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.shortthirdman.quickstart.codesignal;

import java.util.Arrays;

/**
* An integer M and a non-empty array A consisting of N non-negative integers are given.
* All integers in array A are less than or equal to <code>M</code>.
* A pair of integers <code>(P, Q)</code>, such that <code>0 ≤ P ≤ Q < N</code>, is called a slice of array <code>A</code>.
* <br></br>
* The slice consists of the elements A[P], A[P + 1], ..., A[Q]. A distinct slice is a slice consisting of only unique numbers. That is, no individual number occurs more than once in the slice.
* <br></br>
* For example, consider integer M = 6 and array A such that:
* <pre>
* A[0] = 3
* A[1] = 4
* A[2] = 5
* A[3] = 5
* A[4] = 2
* </pre>
* There are exactly nine distinct slices:
* <pre>(0, 0), (0, 1), (0, 2), (1, 1), (1, 2), (2, 2), (3, 3), (3, 4) and (4, 4).</pre>
*
* The goal is to calculate the number of distinct slices.
*
* @author ShortThirdMan
*/
public class CountDistinctSlices {

/**
* Given an integer M and a non-empty array A consisting of N integers, returns the number of distinct slices.
* <br>
* If the number of distinct slices is greater than 1,000,000,000, the function should return 1,000,000,000.
* @param M integer
* @param A non-empty array
* @return number of distinct slices
*/
public int calculateDistinctSlices(int M, int[] A) {
int N = A.length;
if (N < 1 || N > 100000) {
throw new IllegalArgumentException("Array length should be between 1 and 100000");
}

if (M < 0 || M > 100000) {
throw new IllegalArgumentException("Integer M should be between 0 and 100000");
}

boolean isNotInRange = Arrays.stream(A).boxed().anyMatch(n -> n < 0 || n > M);
if (isNotInRange) {
throw new IllegalArgumentException("Each element in array should be between 0 and " + M);
}

int distinctSlices = 0;

if (distinctSlices > 1_000_000_000) {
return 1_000_000_000;
}

return distinctSlices;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.shortthirdman.quickstart.codesignal;


public class EquiLeader {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.shortthirdman.quickstart.codesignal;

import org.junit.jupiter.api.BeforeEach;

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

class CountDistinctSlicesTest {

CountDistinctSlices app;

@BeforeEach
void setUp() {
app = new CountDistinctSlices();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.shortthirdman.quickstart.codesignal;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

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

class EquiLeaderTest {

EquiLeader app;

@BeforeEach
void setUp() {
app = new EquiLeader();
}

@AfterEach
void tearDown() {
}
}

0 comments on commit 7a3207a

Please sign in to comment.