Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cse332-20su/para
  • cse332-20au/para
  • andrese/para
  • cse332-21wi/para
  • ahersi6/para
  • cse332-21sp/para
6 results
Show changes
Commits on Source (8)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="json-simple-1.1.1.jar"/>
<classpathentry kind="lib" path="testing.jar"/>
<classpathentry kind="output" path="bin"/>
......
/bin/
.idea/
*.iml
File added
File added
......@@ -22,7 +22,7 @@ public class FilterEmpty {
throw new NotYetImplementedException();
}
public static int[] mapToOutput(String[] input, int[] bitsum) {
throw new NotYetImplementedException();
}
......
......@@ -23,7 +23,7 @@ public class HasOver {
int[] arr = null;
try {
val = Integer.parseInt(args[0]);
val = Integer.parseInt(args[0]);
String[] stringArr = args[1].replaceAll("\\s*", "").split(",");
arr = new int[stringArr.length];
for (int i = 0; i < stringArr.length; i++) {
......@@ -33,6 +33,6 @@ public class HasOver {
} catch (NumberFormatException e) {
usage();
}
}
}
......@@ -23,7 +23,7 @@ public class LongestSequence {
int[] arr = null;
try {
val = Integer.parseInt(args[0]);
val = Integer.parseInt(args[0]);
String[] stringArr = args[1].replaceAll("\\s*", "").split(",");
arr = new int[stringArr.length];
for (int i = 0; i < stringArr.length; i++) {
......
package tests.gitlab.filterEmpty;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import filterEmpty.FilterEmpty;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import static org.junit.Assert.*;
import cse332.exceptions.NotYetImplementedException;
import filterEmpty.FilterEmpty;
import tests.exceptions.InformativeException;
import tests.TestsUtility;
public class FilterEmptyTests {
public class FilterEmptyTests extends TestsUtility {
public static Random RANDOM = new Random(332134);
public static final int NUM_SMALL = 250;
......@@ -22,41 +20,24 @@ public class FilterEmptyTests extends TestsUtility {
public static final int MAX_STRING_LENGTH = 30;
public static void main(String[] args) {
new FilterEmptyTests().run();
}
protected void run() {
END_WITH_EXIT = true;
SHOW_TESTS = true;
ALLOWED_TIME = 15000;
test("checkSmall");
test("checkLarge");
finish();
}
public static int checkSmall() {
boolean good = true;
@Test(timeout = 15000)
public void testSmall() {
for (int i = 0; i < NUM_SMALL; i++) {
String[] input = makeInput(i, SMALL_SIZE);
int[] output = filter(input);
good &= runTest(input, output) == 1;
runTest(input, output);
}
return good ? 1 : 0;
}
public static int checkLarge() {
boolean good = true;
@Test(timeout = 15000)
public void testLarge() {
for (int i = 0; i < NUM_LARGE; i++) {
String[] input = makeRandomInput(LARGE_SIZE);
good &= runTest(input, filter(input)) == 1;
runTest(input, filter(input));
}
return good ? 1 : 0;
}
private static String makeStringOfLength(int length) {
private String makeStringOfLength(int length) {
StringBuilder str = new StringBuilder();
for (int i = 0; i < length; i++) {
str.append("" + ('a' + RANDOM.nextInt(26)));
......@@ -64,7 +45,7 @@ public class FilterEmptyTests extends TestsUtility {
return str.toString();
}
private static String[] makeInput(int num, int size) {
private String[] makeInput(int num, int size) {
String[] input = new String[size];
for (int i = size - 1; i >= 0; i--) {
input[i] = ((num >> i) & 1) == 1 ? makeStringOfLength(RANDOM.nextInt(MAX_STRING_LENGTH) + 1) : "";
......@@ -72,7 +53,7 @@ public class FilterEmptyTests extends TestsUtility {
return input;
}
private static int[] filter(String[] input) {
private int[] filter(String[] input) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < input.length; i++) {
if (input[i].length() > 0) {
......@@ -86,7 +67,7 @@ public class FilterEmptyTests extends TestsUtility {
return ret;
}
private static String[] makeRandomInput(int size) {
private String[] makeRandomInput(int size) {
String[] input = new String[size];
for (int i = size - 1; i >= 0; i--) {
input[i] = RANDOM.nextBoolean() ? makeStringOfLength(RANDOM.nextInt(MAX_STRING_LENGTH) + 1) : "";
......@@ -94,12 +75,14 @@ public class FilterEmptyTests extends TestsUtility {
return input;
}
private static int runTest(String[] input, int[] expected) {
private void runTest(String[] input, int[] expected) {
String inputString = Arrays.toString(input);
if (inputString.length() > 0) {
inputString = inputString.substring(1, inputString.length() - 1);
}
String result = runMain(FilterEmpty.class, new String[]{inputString}).trim();
return (result != null && result.equals(Arrays.toString(expected))) ? 1 : 0;
String[] arr = inputString.replaceAll("\\s*", "").split(",");
int[] result = FilterEmpty.filterEmpty(arr);
assertNotNull(result);
assertEquals(Arrays.toString(expected), Arrays.toString(result));
}
}
package tests.gitlab.getLeftMostIndex;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
import cse332.exceptions.NotYetImplementedException;
import getLeftMostIndex.GetLeftMostIndex;
import tests.exceptions.InformativeException;
import tests.TestsUtility;
import org.junit.Test;
import static org.junit.Assert.*;
public class GetLeftMostIndexTests extends TestsUtility {
public class GetLeftMostIndexTests {
public static Random RANDOM = new Random(332134);
public static final int FULLY_SEQUENTIAL = Integer.MAX_VALUE;
......@@ -24,78 +20,31 @@ public class GetLeftMostIndexTests extends TestsUtility {
public static final int LARGE_NEEDLE_SIZE = 10;
public static final int LARGE_HAYSTACK_SIZE = 100000;
public static final int HUGE_NEEDLE_SIZE = 50;
public static final int HUGE_HAYSTACK_SIZE = 80000000;
public static void main(String[] args) {
new GetLeftMostIndexTests().run();
}
protected void run() {
END_WITH_EXIT = true;
SHOW_TESTS = true;
ALLOWED_TIME = 25000;
test("checkSmallSequential");
test("checkSmallParallel");
test("checkLarge");
finish();
}
public static int checkSmallSequential() {
boolean good = true;
@Test(timeout = 25000)
public void checkSmallSequential() {
for (int i = 0; i < NUM_SMALL_HAYSTACKS; i++) {
for (int j = 1; j <= NUM_SMALL_NEEDLE_SIZES; j++) {
good &= test(makeInput(i, SMALL_HAYSTACK_SIZE), FULLY_SEQUENTIAL, j);
test(makeInput(i, SMALL_HAYSTACK_SIZE), FULLY_SEQUENTIAL, j);
}
}
return good ? 1 : 0;
}
public static int checkSmallParallel() {
boolean good = true;
@Test(timeout = 25000)
public void checkSmallParallel() {
for (int i = 0; i < NUM_SMALL_HAYSTACKS; i++) {
for (int j = 1; j <= NUM_SMALL_NEEDLE_SIZES; j++) {
good &= test(makeInput(i, SMALL_HAYSTACK_SIZE), FULLY_PARALLEL, j);
test(makeInput(i, SMALL_HAYSTACK_SIZE), FULLY_PARALLEL, j);
}
}
return good ? 1 : 0;
}
public static int checkLarge() {
boolean good = true;
@Test(timeout = 25000)
public void checkLarge() {
for (int i = 0; i < NUM_LARGE_HAYSTACKS; i++) {
good &= test(makeRandomInput(LARGE_HAYSTACK_SIZE), REASONABLE_CUTOFF, LARGE_NEEDLE_SIZE);
test(makeRandomInput(LARGE_HAYSTACK_SIZE), REASONABLE_CUTOFF, LARGE_NEEDLE_SIZE);
}
return good ? 1 : 0;
}
public static int checkParallelism() {
String haystack = makeRandomInput(HUGE_HAYSTACK_SIZE);
String needle = makeRandomInput(HUGE_NEEDLE_SIZE);
int answer = sweep(needle, haystack);
long seqTime, reasonableTime, paraTime = 0;
long start = System.currentTimeMillis();
boolean fullySequential = runTest(needle, haystack, FULLY_SEQUENTIAL, answer) == 1;
seqTime = System.currentTimeMillis() - start;
boolean reasonableCutoff = runTest(needle, haystack, REASONABLE_CUTOFF, answer) == 1;
reasonableTime = System.currentTimeMillis() - (seqTime + start);
boolean fullyParallel = runTest(needle, haystack, FULLY_PARALLEL, answer) == 1;
paraTime = System.currentTimeMillis() - (seqTime + reasonableTime + start);
if (!fullySequential || !reasonableCutoff || !fullyParallel) {
return 0;
}
return (paraTime > seqTime && seqTime > reasonableTime) ? 1 : 0;
}
private static int sweep(String needle, String haystack) {
int currStart = 0;
int needleIndex = 0;
......@@ -120,7 +69,7 @@ public class GetLeftMostIndexTests extends TestsUtility {
return -1;
}
private static String makeInput(int num, int size) {
private String makeInput(int num, int size) {
StringBuilder arr = new StringBuilder();
for (int i = size - 1; i >= 0; i--) {
arr.append("" + (char)('0' + (char)((num >> i) & 1)));
......@@ -128,7 +77,7 @@ public class GetLeftMostIndexTests extends TestsUtility {
return arr.toString();
}
private static String makeRandomInput(int size) {
private String makeRandomInput(int size) {
StringBuilder arr = new StringBuilder();
for (int i = size - 1; i >= 0; i--) {
arr.append("" + (char)('0' + (RANDOM.nextBoolean() ? 1 : 0)));
......@@ -137,17 +86,12 @@ public class GetLeftMostIndexTests extends TestsUtility {
}
private static boolean test(String haystack, int cutoff, int needleSize) {
boolean correct = true;
private void test(String haystack, int cutoff, int needleSize) {
for (int i = 0; i < (1 << needleSize); i++) {
String needle = makeInput(i, needleSize);
correct &= runTest(needle, haystack, cutoff, sweep(needle, haystack)) == 1;
int actual = GetLeftMostIndex.getLeftMostIndex(needle.toCharArray(), haystack.toCharArray(), cutoff);
int expected = sweep(needle, haystack);
assertEquals(expected, actual);
}
return correct;
}
private static int runTest(String needle, String haystack, int cutoff, int expected) {
return GetLeftMostIndex.getLeftMostIndex(needle.toCharArray(), haystack.toCharArray(), cutoff) == expected ? 1 :0;
}
}
package tests.gitlab.hasOver;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
import cse332.exceptions.NotYetImplementedException;
import hasOver.HasOver;
import tests.exceptions.InformativeException;
import tests.TestsUtility;
import org.junit.Test;
import static org.junit.Assert.*;
public class HasOverTests extends TestsUtility {
public class HasOverTests {
public static int[] TEST_ARRAY_0 = new int[] {2, 17, 19, 8, 21, 17, 35, 0, 4, 1};
public static int[] TEST_ARRAY_1 = new int[] {-2, -17, -19, -8, -21, -17, -35, -4, -1};
public static Random RANDOM = new Random(332134);
......@@ -25,85 +23,119 @@ public class HasOverTests extends TestsUtility {
public static final int LARGE_MAX = 1000;
public static final int HUGE_SIZE = 6000000;
public static final int ALLOWED_TIME = 19000;
@Test(timeout = ALLOWED_TIME)
public void tiny1() {
runTest(17, TEST_ARRAY_0, true);
}
public static void main(String[] args) {
new HasOverTests().run();
@Test(timeout = ALLOWED_TIME)
public void tiny2() {
runTest(35, TEST_ARRAY_0, false);
}
protected void run() {
END_WITH_EXIT = true;
SHOW_TESTS = true;
@Test(timeout = ALLOWED_TIME)
public void tiny3() {
runTest(40, TEST_ARRAY_0, false);
}
ALLOWED_TIME = 19000;
@Test(timeout = ALLOWED_TIME)
public void negative1() {
runTest(-17, TEST_ARRAY_1, true);
}
for (int i = 1; i < 4; i++) {
test("tiny" + i);
test("negative" + i);
}
@Test(timeout = ALLOWED_TIME)
public void negative2() {
runTest(-1, TEST_ARRAY_1, false);
}
for (int i = 1; i < 9; i++) {
test("medium" + i);
test("large" + i);
}
@Test(timeout = ALLOWED_TIME)
public void negative3() {
runTest(0, TEST_ARRAY_1, false);
}
finish();
@Test(timeout = ALLOWED_TIME)
public void medium1() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, -1), false);
}
public static int tiny1() { return runTest(17, TEST_ARRAY_0, true); }
public static int tiny2() { return runTest(35, TEST_ARRAY_0, false); }
public static int tiny3() { return runTest(40, TEST_ARRAY_0, false); }
public static int negative1() { return runTest(-17, TEST_ARRAY_1, true); }
public static int negative2() { return runTest(-1, TEST_ARRAY_1, false); }
public static int negative3() { return runTest(0, TEST_ARRAY_1, false); }
@Test(timeout = ALLOWED_TIME)
public void medium2() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, 0), true);
}
@Test(timeout = ALLOWED_TIME)
public void medium3() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE - 1), true);
}
public static int medium1() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, -1), false); }
public static int medium2() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, 0), true); }
public static int medium3() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE - 1), true); }
public static int medium4() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 2), true); }
public static int medium5() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 4 - 1), true); }
public static int medium6() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 2 + 17), true); }
public static int medium7() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, 17), true); }
public static int medium8() { return runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, -1), false); }
@Test(timeout = ALLOWED_TIME)
public void medium4() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 2), true);
}
public static int large1() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, -1), false); }
public static int large2() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, 0), true); }
public static int large3() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE - 1), true); }
public static int large4() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 2), true); }
public static int large5() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 4 - 1), true); }
public static int large6() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 2 + 17), true); }
public static int large7() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, 17), true); }
public static int large8() { return runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, -1), false); }
@Test(timeout = ALLOWED_TIME)
public void medium5() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 4 - 1), true);
}
public static int checkParallelism() {
int best = 0, conseq = 0;
int[] input = create(HUGE_SIZE, LARGE_MAX, -1);
@Test(timeout = ALLOWED_TIME)
public void medium6() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, MEDIUM_SIZE / 2 + 17), true);
}
long seqTime, reasonableTime, paraTime = 0;
long start = System.currentTimeMillis();
@Test(timeout = ALLOWED_TIME)
public void medium7() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, 17), true);
}
boolean fullySequential = runTest(LARGE_MAX, input, false, FULLY_SEQUENTIAL) == 1;
seqTime = System.currentTimeMillis() - start;
@Test(timeout = ALLOWED_TIME)
public void medium8() {
runTest(MEDIUM_MAX, create(MEDIUM_SIZE, MEDIUM_MAX, -1), false);
}
boolean reasonableCutoff = runTest(LARGE_MAX, input, false, REASONABLE_CUTOFF) == 1;
reasonableTime = System.currentTimeMillis() - (seqTime + start);
@Test(timeout = ALLOWED_TIME)
public void large1() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, -1), false);
}
boolean fullyParallel = runTest(LARGE_MAX, input, false, FULLY_PARALLEL) == 1;
paraTime = System.currentTimeMillis() - (reasonableTime + seqTime + start);
@Test(timeout = ALLOWED_TIME)
public void large2() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, 0), true);
}
if (!fullySequential || !reasonableCutoff || !fullyParallel) {
return 0;
}
@Test(timeout = ALLOWED_TIME)
public void large3() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE - 1), true);
}
double seq = seqTime;
double reasonable = reasonableTime;
double para = paraTime;
@Test(timeout = ALLOWED_TIME)
public void large4() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 2), true);
}
@Test(timeout = ALLOWED_TIME)
public void large5() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 4 - 1), true);
}
return (seq > para && para > reasonable) ? 1 : 0;
@Test(timeout = ALLOWED_TIME)
public void large6() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, LARGE_SIZE / 2 + 17), true);
}
public static int[] create(int size, int max, int where) {
@Test(timeout = ALLOWED_TIME)
public void large7() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, 17), true);
}
@Test(timeout = ALLOWED_TIME)
public void large8() {
runTest(LARGE_MAX, create(LARGE_SIZE, LARGE_MAX, -1), false);
}
public int[] create(int size, int max, int where) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
......@@ -118,16 +150,8 @@ public class HasOverTests extends TestsUtility {
return array;
}
private static int runTest(int num, int[] array, boolean expected) {
return runTest(num, array, expected, REASONABLE_CUTOFF);
}
private static int runTest(int num, int[] array, boolean expected, int cutoff) {
String numString = Integer.toString(num);
String arrayString = Arrays.toString(array);
arrayString = arrayString.substring(1, arrayString.length() - 1);
String cutoffString = Integer.toString(cutoff);
String result = runMain(HasOver.class, new String[]{numString, arrayString, cutoffString}).trim();
return (result != null && result.equals(expected ? "true" : "false")) ? 1 : 0;
private void runTest(int num, int[] array, boolean expected) {
boolean actual = HasOver.hasOver(num, array, REASONABLE_CUTOFF);
assertEquals(expected, actual);
}
}
package tests.gitlab.longestSequence;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
import cse332.exceptions.NotYetImplementedException;
import longestSequence.LongestSequence;
import tests.exceptions.InformativeException;
import tests.TestsUtility;
import org.junit.Test;
public class LongestSequenceTests extends TestsUtility {
import static org.junit.Assert.*;
public class LongestSequenceTests {
public static Random RANDOM = new Random(332134);
public static final int FULLY_SEQUENTIAL = Integer.MAX_VALUE;
......@@ -22,88 +19,31 @@ public class LongestSequenceTests extends TestsUtility {
public static final int SMALL_SIZE = 100;
public static final int LARGE_SIZE = 100000;
public static final int HUGE_SIZE = 300000000;
public static void main(String[] args) {
new LongestSequenceTests().run();
}
protected void run() {
END_WITH_EXIT = true;
SHOW_TESTS = true;
PRINT_STDERR = true;
PRINT_TESTERR = true;
ALLOWED_TIME = 25000;
test("checkSmallSequential");
test("checkSmallParallel");
test("checkLarge");
finish();
}
public static int checkSmallSequential() {
boolean good = true;
@Test(timeout = 25000)
public void testSmallSequential() {
for (int i = 0; i < NUM_SMALL_TESTS; i++) {
good &= testSmallBitArray(i, FULLY_SEQUENTIAL, 0);
good &= testSmallBitArray(i, FULLY_SEQUENTIAL, 1);
testSmallBitArray(i, FULLY_SEQUENTIAL, 0);
testSmallBitArray(i, FULLY_SEQUENTIAL, 1);
}
return good ? 1 : 0;
}
public static int checkSmallParallel() {
boolean good = true;
@Test(timeout = 25000)
public void testSmallParallel() {
for (int i = 0; i < NUM_SMALL_TESTS; i++) {
good &= testSmallBitArray(i, FULLY_PARALLEL, 0);
good &= testSmallBitArray(i, FULLY_PARALLEL, 1);
testSmallBitArray(i, FULLY_PARALLEL, 0);
testSmallBitArray(i, FULLY_PARALLEL, 1);
}
return good ? 1 : 0;
}
public static int checkLarge() {
boolean good = true;
@Test(timeout = 25000)
public void testLarge() {
for (int i = 0; i < NUM_LARGE_TESTS; i++) {
good &= testRandomBitArray(LARGE_SIZE, REASONABLE_CUTOFF, 0);
good &= testRandomBitArray(LARGE_SIZE, REASONABLE_CUTOFF, 1);
}
return good ? 1 : 0;
}
public static int checkParallelism() {
int best = 0, conseq = 0;
int[] bits = new int[HUGE_SIZE];
for (int i = 0; i < HUGE_SIZE; i++) {
bits[i] = RANDOM.nextBoolean() ? 1 : 0;
if (bits[i] == 0) {
conseq++;
}
else {
conseq = 0;
}
best = Math.max(best, conseq);
}
long seqTime, reasonableTime, paraTime = 0;
long start = System.currentTimeMillis();
boolean fullySequential = runTest(0, bits, FULLY_SEQUENTIAL, best) == 1;
seqTime = System.currentTimeMillis() - start;
boolean reasonableCutoff = runTest(0, bits, REASONABLE_CUTOFF, best) == 1;
reasonableTime = System.currentTimeMillis() - (seqTime + start);
boolean fullyParallel = runTest(0, bits, FULLY_PARALLEL, best) == 1;
paraTime = System.currentTimeMillis() - (reasonableTime + seqTime + start);
if (!fullySequential || !reasonableCutoff || !fullyParallel) {
return 0;
testRandomBitArray(LARGE_SIZE, REASONABLE_CUTOFF, 0);
testRandomBitArray(LARGE_SIZE, REASONABLE_CUTOFF, 1);
}
return (paraTime > seqTime && seqTime > reasonableTime) ? 1 : 0;
}
private static boolean testSmallBitArray(int num, int cutoff, int match) {
private void testSmallBitArray(int num, int cutoff, int match) {
int best = 0;
int conseq = 0;
int[] bits = new int[SMALL_SIZE];
......@@ -117,10 +57,11 @@ public class LongestSequenceTests extends TestsUtility {
}
best = Math.max(best, conseq);
}
return runTest(match, bits, cutoff, best) == 1;
int actual = LongestSequence.getLongestSequence(match, bits, cutoff);
assertEquals(best, actual);
}
private static boolean testRandomBitArray(int size, int cutoff, int match) {
private void testRandomBitArray(int size, int cutoff, int match) {
int best = 0;
int conseq = 0;
int[] bits = new int[size];
......@@ -134,10 +75,7 @@ public class LongestSequenceTests extends TestsUtility {
}
best = Math.max(best, conseq);
}
return runTest(match, bits, cutoff, best) == 1;
}
private static int runTest(int num, int[] array, int cutoff, int expected) {
return LongestSequence.getLongestSequence(num, array, cutoff) == expected ? 1 : 0;
int actual = LongestSequence.getLongestSequence(match, bits, cutoff);
assertEquals(best, actual);
}
}
No preview for this file type