-
Notifications
You must be signed in to change notification settings - Fork 596
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
Unit tests for Utils.concat() #7918
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bd8ff3
unit tests for concat 2 methods (multiple byte arrays, 2 byte arrays)
orlicohen 9e779d6
Added data providers/unit tests for 3 versions of concat()
orlicohen 5906c81
updated test case
orlicohen 428a1a1
added edge test cases
orlicohen f7eb396
responding to review comments
orlicohen 7c5025c
updated unit tests
orlicohen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import com.google.common.primitives.Ints; | ||
import htsjdk.samtools.util.Log.LogLevel; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.apache.logging.log4j.Level; | ||
import org.broadinstitute.hellbender.GATKBaseTest; | ||
import org.broadinstitute.hellbender.utils.io.IOUtils; | ||
|
@@ -18,6 +19,7 @@ | |
import java.io.File; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.*; | ||
import java.util.function.IntFunction; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
|
@@ -978,4 +980,81 @@ public void testTestFilterCollectionByExpressions(Set<String> values, Collection | |
Set<String> actual = Utils.filterCollectionByExpressions(values, filters, exactMatch); | ||
Assert.assertEquals(actual, expected); | ||
} | ||
|
||
@DataProvider(name = "concatMultipleByteArraysData") | ||
public Object[][] concatMultipleByteArraysData() { | ||
return new Object[][]{ | ||
// expected, arrays | ||
new Object[]{ ArrayUtils.EMPTY_BYTE_ARRAY, new byte[] { } }, | ||
new Object[]{ new byte[] {100, 100}, new byte[] {100, 100} }, | ||
new Object[]{ new byte[] {100, 100, 10, 10}, new byte[] {100, 100}, new byte[] { }, new byte[] {10,10} }, | ||
new Object[]{ ArrayUtils.EMPTY_BYTE_ARRAY, new byte[] { }, new byte[] { }, new byte[] { } }, | ||
new Object[]{ new byte[] {12, 10, 15, 15, 20, 20}, new byte[] {12, 10}, new byte[] {15, 15}, new byte[] {20, 20} }, | ||
}; | ||
} | ||
|
||
// expected listed first to accomodate varargs arrays having to be last parameter | ||
@Test(dataProvider = "concatMultipleByteArraysData") | ||
public void testConcatMultipleByteArrays(byte[] expected, byte[] ... arrays) { | ||
Assert.assertEquals(Utils.concat(arrays), expected); | ||
} | ||
|
||
@Test | ||
public void testConcatMultipleWithNoArrays(){ | ||
Assert.assertEquals(Utils.concat(), ArrayUtils.EMPTY_BYTE_ARRAY); | ||
} | ||
|
||
@DataProvider(name = "concatTwoByteArraysData") | ||
public Object[][] concatTwoByteArraysData() { | ||
return new Object[][]{ | ||
// arr1, arr2, expected | ||
new Object[]{ new byte[] { }, new byte[] { }, ArrayUtils.EMPTY_BYTE_ARRAY }, | ||
new Object[]{ new byte[] {10, 10}, new byte[] { }, new byte[] {10, 10} }, | ||
new Object[]{ new byte[] { }, new byte[] {10, 10}, new byte[] {10, 10} }, | ||
new Object[]{ new byte[] {10}, new byte[] {15, 15}, new byte[] {10, 15, 15} }, | ||
new Object[]{ new byte[] {12, 10}, new byte[] {15, 15}, new byte[] {12, 10, 15, 15} }, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "concatTwoByteArraysData") | ||
public void testConcatTwoByteArrays(byte[] arr1, byte[] arr2, byte[] expected) { | ||
Assert.assertEquals(Utils.concat(arr1, arr2), expected); | ||
} | ||
|
||
@DataProvider(name = "concatAnyTypeArraysData") | ||
public Object[][] concatAnyTypeArraysData() { | ||
return new Object[][]{ | ||
// arr1, arr2, constructor, expected | ||
new Object[]{ new Integer[] { }, new Integer[] { }, (IntFunction<Integer[]>)Integer[]::new, | ||
new Integer[] { } }, | ||
new Object[]{ new Integer[] {1, 2, 3}, new Integer[] { }, (IntFunction<Integer[]>)Integer[]::new, | ||
new Integer[] {1, 2, 3} }, | ||
new Object[]{ new Integer[] { }, new Integer[] {4, 5, 6}, (IntFunction<Integer[]>)Integer[]::new, | ||
new Integer[] {4, 5, 6} }, | ||
new Object[]{ new Integer[] {1, 2, 3}, new Integer[] {4, 5, 6}, (IntFunction<Integer[]>)Integer[]::new, | ||
new Integer[] {1, 2, 3, 4, 5, 6} }, | ||
new Object[]{ new Integer[] {4, 5, 6}, new Integer[] {1, 2, 3}, (IntFunction<Integer[]>)Integer[]::new, | ||
new Integer[] {4, 5, 6, 1, 2, 3} }, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments on the test cases for the generic version of concat():
|
||
} | ||
|
||
@Test(dataProvider = "concatAnyTypeArraysData") | ||
public void testConcatAnyTypeArrays(Integer[] arr1, Integer[] arr2, IntFunction<Integer[]> constructor, Integer[] expected) { | ||
Assert.assertEquals(Utils.concat(arr1, arr2, constructor), expected); | ||
} | ||
|
||
@DataProvider(name = "concatAnyTypeWithNullArrayData") | ||
public Object[][] concatAnyTypeWithNullArrayData(){ | ||
return new Object[][]{ | ||
new Object[]{null, new Integer[] {1, 2, 3}, (IntFunction<Integer[]>) Integer[]::new}, | ||
new Object[]{new Integer[] {1, 2, 3}, null, (IntFunction<Integer[]>) Integer[]::new}, | ||
new Object[]{null, null, (IntFunction<Integer[]>) Integer[]::new} | ||
}; | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "concatAnyTypeWithNullArrayData") | ||
public void testConcatAnyTypeWithNullArray(Integer[] arr1, Integer[] arr2, IntFunction<Integer[]> constructor){ | ||
Utils.concat(arr1, arr2, constructor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null tests look good 👍 |
||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments on the test cases for the varargs version of concat():