Skip to content

Instantly share code, notes, and snippets.

@CoolgaDV
Created April 24, 2020 13:07
Show Gist options
  • Select an option

  • Save CoolgaDV/9d2e517a6adba0742d81b713569d4fb1 to your computer and use it in GitHub Desktop.

Select an option

Save CoolgaDV/9d2e517a6adba0742d81b713569d4fb1 to your computer and use it in GitHub Desktop.
Merge sort test suite (interview task)
package interview;
import java.util.Arrays;
class MergeSortTest {
public static void main(String[] args) {
int[][] sourceData = {
{ },
{ 1 },
{ 1, 1, 1 },
{ 1, 2, 3 },
{ 3, 2, 1 },
{ 0, -1, 1 },
{ 80, 9, 1, 5 },
{ 1, 10, 8, 4, 8 }
};
int[][] expectedData = {
{ },
{ 1 },
{ 1, 1, 1 },
{ 1, 2, 3 },
{ 1, 2, 3 },
{ -1, 0, 1 },
{ 1, 5, 9, 80 },
{ 1, 4, 8, 8, 10 }
};
MergeSort sort = new MergeSort();
for (int i = 0; i < sourceData.length; i++) {
int[] source = sourceData[i];
int[] test = new int[source.length];
System.arraycopy(source, 0, test, 0, source.length);
int[] expected = expectedData[i];
sort.sort(test);
if (!Arrays.equals(test, expected)) {
throw new RuntimeException(
"Sort failed. Source data set: " + Arrays.toString(source) +
", expected result: " + Arrays.toString(expected) +
", actual result: " + Arrays.toString(test));
}
System.out.println("Case number " + i + " succeeded");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment