Skip to content
Open
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
20 changes: 19 additions & 1 deletion epi_judge_java/epi/LongestIncreasingSubarray.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package epi;
import epi.test_framework.EpiTest;
import epi.test_framework.GenericTest;
import epi.test_framework.TestFailure;

import java.util.List;
public class LongestIncreasingSubarray {
Expand All @@ -20,9 +21,26 @@ public static Subarray findLongestIncreasingSubarray(List<Integer> A) {
// TODO - you fill in here.
return new Subarray(0, 0);
}

@EpiTest(testDataFile = "longest_increasing_subarray.tsv")
public static int findLongestIncreasingSubarrayWrapper(List<Integer> A) {
public static int findLongestIncreasingSubarrayWrapper(List<Integer> A)
throws Exception {
Subarray result = findLongestIncreasingSubarray(A);

if (result.start < 0 || result.start >= A.size() ||
result.end < 0 || result.end >= A.size() ||
result.start > result.end)
throw new TestFailure("Index out of range");

for (int i = result.start + 1; i < result.end; ++i) {
if (A.get(i) <= A.get(i - 1)) {
throw new TestFailure()
.withMismatchInfo(
i, String.format("A[%d] < A[%d]", i - 1, i),
String.format("%d >= %d", A.get(i - 1), A.get(i)));
}
}

return result.end - result.start + 1;
}

Expand Down
19 changes: 18 additions & 1 deletion epi_judge_java_solutions/epi/LongestIncreasingSubarray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import epi.test_framework.EpiTest;
import epi.test_framework.GenericTest;
import epi.test_framework.TestFailure;

import java.util.List;

Expand Down Expand Up @@ -48,8 +49,24 @@ public static Subarray findLongestIncreasingSubarray(List<Integer> A) {
}

@EpiTest(testDataFile = "longest_increasing_subarray.tsv")
public static int findLongestIncreasingSubarrayWrapper(List<Integer> A) {
public static int findLongestIncreasingSubarrayWrapper(List<Integer> A)
throws Exception {
Subarray result = findLongestIncreasingSubarray(A);

if (result.start < 0 || result.start >= A.size() ||
result.end < 0 || result.end >= A.size() ||
result.start > result.end)
throw new TestFailure("Index out of range");

for (int i = result.start + 1; i < result.end; ++i) {
if (A.get(i) <= A.get(i - 1)) {
throw new TestFailure()
.withMismatchInfo(
i, String.format("A[%d] < A[%d]", i - 1, i),
String.format("%d >= %d", A.get(i - 1), A.get(i)));
}
}

return result.end - result.start + 1;
}

Expand Down