Skip to content
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

Fix: Ignore order on task pairing checks #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
41 changes: 40 additions & 1 deletion epi_judge_java/epi/TaskPairing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import epi.test_framework.EpiTest;
import epi.test_framework.EpiUserType;
import epi.test_framework.GenericTest;
import epi.test_framework.EpiTestComparator;

import java.util.List;
import java.util.Comparator;

public class TaskPairing {
@EpiUserType(ctorParams = {Integer.class, Integer.class})

Expand All @@ -27,7 +30,8 @@ public boolean equals(Object o) {

PairedTasks that = (PairedTasks)o;

return task1.equals(that.task1) && task2.equals(that.task2);
return task1.equals(that.task1) && task2.equals(that.task2) ||
task1.equals(that.task2) && task2.equals(that.task1);
}

@Override
Expand All @@ -36,6 +40,31 @@ public String toString() {
}
}

private static class PairedTasksComparator implements Comparator<PairedTasks> {
@Override
public int compare(PairedTasks p1, PairedTasks p2) {
if (p1 == null) {
return p2 == null ? 0 : -1;
}

if (p1.equals(p2)) {
return 0;
}

Integer minP1 = Math.min(p1.task1, p1.task2);
Integer minP2 = Math.min(p2.task1, p2.task2);
int minCompare = minP1.compareTo(minP2);

if (minCompare != 0) {
return minCompare;
} else {
Integer maxP1 = Math.max(p1.task1, p1.task2);
Integer maxP2 = Math.max(p2.task1, p2.task2);
return maxP1.compareTo(maxP2);
}
}
}

@EpiTest(testDataFile = "task_pairing.tsv")

public static List<PairedTasks>
Expand All @@ -44,6 +73,16 @@ public String toString() {
return null;
}

@EpiTestComparator
public static boolean comp(List<PairedTasks> expected, List<PairedTasks> result) {
if (result == null) {
return false;
}
result.sort(new PairedTasksComparator());
expected.sort(new PairedTasksComparator());
return expected.equals(result);
}

public static void main(String[] args) {
System.exit(
GenericTest
Expand Down
40 changes: 39 additions & 1 deletion epi_judge_java_solutions/epi/TaskPairing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import epi.test_framework.EpiTest;
import epi.test_framework.EpiUserType;
import epi.test_framework.GenericTest;
import epi.test_framework.EpiTestComparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TaskPairing {
Expand All @@ -31,7 +33,8 @@ public boolean equals(Object o) {

PairedTasks that = (PairedTasks)o;

return task1.equals(that.task1) && task2.equals(that.task2);
return task1.equals(that.task1) && task2.equals(that.task2) ||
task1.equals(that.task2) && task2.equals(that.task1);
}

@Override
Expand All @@ -40,6 +43,31 @@ public String toString() {
}
}

private static class PairedTasksComparator implements Comparator<PairedTasks> {
@Override
public int compare(PairedTasks p1, PairedTasks p2) {
if (p1 == null) {
return p2 == null ? 0 : -1;
}

if (p1.equals(p2)) {
return 0;
}

Integer minP1 = Math.min(p1.task1, p1.task2);
Integer minP2 = Math.min(p2.task1, p2.task2);
int minCompare = minP1.compareTo(minP2);

if (minCompare != 0) {
return minCompare;
} else {
Integer maxP1 = Math.max(p1.task1, p1.task2);
Integer maxP2 = Math.max(p2.task1, p2.task2);
return maxP1.compareTo(maxP2);
}
}
}

@EpiTest(testDataFile = "task_pairing.tsv")

public static List<PairedTasks>
Expand All @@ -54,6 +82,16 @@ public String toString() {
return optimumAssignments;
}

@EpiTestComparator
public static boolean comp(List<PairedTasks> expected, List<PairedTasks> result) {
if (result == null) {
return false;
}
result.sort(new PairedTasksComparator());
expected.sort(new PairedTasksComparator());
return expected.equals(result);
}

public static void main(String[] args) {
System.exit(
GenericTest
Expand Down