Skip to content

Commit

Permalink
Improve CLI
Browse files Browse the repository at this point in the history
Simply return error code 1 instead of showing a traceback
  • Loading branch information
Gaming32 committed Oct 31, 2021
1 parent f234713 commit c5ed8e0
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.Comparator;

public class Tester {
static class SortFailedException extends Exception {
}

static interface IntegerPair {
public Integer getKey();
public Integer getValue();
Expand Down Expand Up @@ -93,7 +96,7 @@ else if(!this.keyArray[i - 1].equals(this.referenceArray[i - 1])) {
return true;
}

private void checkAlgorithm(int start, int length, int keyCount, boolean grailSort, int grailBufferType, String grailStrategy, GrailComparator test) throws Exception {
private void checkAlgorithm(int start, int length, int keyCount, boolean grailSort, int grailBufferType, String grailStrategy, GrailComparator test) throws SortFailedException {
this.generateTestArray(start, length, keyCount);
this.referenceArray = Arrays.copyOf(this.keyArray, start + length);

Expand Down Expand Up @@ -154,7 +157,7 @@ else if(grailBufferType == 2) {
}
else {
System.out.print(" but the sort was NOT successful!!\nReason: " + this.failReason);
throw new Exception();
throw new SortFailedException();
}

// Sometimes the garbage collector wasn't cooperating.
Expand All @@ -164,7 +167,7 @@ else if(grailBufferType == 2) {
System.gc();
}

private void checkBoth(int start, int length, int keyCount, String grailStrategy, GrailComparator test) throws Exception {
private void checkBoth(int start, int length, int keyCount, String grailStrategy, GrailComparator test) throws SortFailedException {
int tempSeed = this.seed;
if(!grailStrategy.equals("Opti.Gnome")) {
for(int i = 0; i < 3; i++) {
Expand Down Expand Up @@ -252,10 +255,9 @@ public static void main(String[] args) {
testClass.checkBoth( 0, 15, 4, "Opti.Gnome", testCompare);

System.out.println("\nAll tests passed successfully!!");
}
catch (Exception e) {
} catch (SortFailedException e) {
System.out.println("\nTesting failed!!\n");
e.printStackTrace();
System.exit(1);
}
}
}

0 comments on commit c5ed8e0

Please sign in to comment.