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

Adding support for 0-length B arrays in SAM files to conform to 1.6 spec #1194

Merged
merged 20 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion src/test/java/htsjdk/samtools/TextTagCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void testEmptyAndNonEmptyArrayEncoding(Object array, boolean isSigned, St
? textTagCodec.encode(tagName, array)
: textTagCodec.encodeUnsignedArray(tagName, array);
Assert.assertEquals(encodedTag, expectedTag);

}

@DataProvider
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/htsjdk/tribble/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,4 @@ public static Path getTribbleFileInJimfs(String vcf, String index, FileSystem fi
}
return Files.copy(vcfPath, vcfDestination);
}


}
4 changes: 4 additions & 0 deletions src/test/java/htsjdk/utils/TestNGUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static Iterator<Object[]> getDataProviders(final String packageName) {
}

/**
* Combine two or more Dataproviders by taking the cartesian product of the their test cases.
*
* Note: In the case of a an empty provider, the result will be the product of the non-empty providers.
* This isdifferent from the traditional definition of the cartesian product.
lbergelson marked this conversation as resolved.
Show resolved Hide resolved
* @return the cartesian product of two or more DataProviders than can be used as a new dataprovider
*/
public static Object[][] cartesianProduct(Object[][]... dataProviders) {
Expand Down
57 changes: 56 additions & 1 deletion src/test/java/htsjdk/utils/TestNGUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class TestNGUtilsTest extends HtsjdkTest {

public static final Object[] EMPTY_ARRAY = new Object[0];

@DataProvider
public Object[][] getArraysAndLists() {
return new Object[][]{
Expand Down Expand Up @@ -80,11 +83,19 @@ public Object[][] getDataProviders() {
return new Object[][]{
{new Object[][]{{1, 2}}, new Object[][]{{3}, {4}}, new Object[][]{{1, 2, 3}, {1, 2, 4}}},
{new Object[][]{{1}}, new Object[][]{{2}}, new Object[][]{{1, 2}}},
{new Object[][]{{1}}, new Object[][]{{2, 3}}, new Object[][]{{1, 2, 3}}},
{new Object[][]{{1}, {2}, {3}}, new Object[][]{{'a', 'b'}, {'c', 'd'}},
new Object[][]{{1, 'a', 'b'}, {1, 'c', 'd'},
{2, 'a', 'b'}, {2, 'c', 'd'},
{3, 'a', 'b'}, {3, 'c', 'd'}}},
{new Object[][]{ new Object[0], new Object[0], new Object[0]}}
{new Object[][]{{}}, new Object[][]{{}}, new Object[][]{{}}},
{new Object[][]{{}}, new Object[][]{{1}}, new Object[][]{{1}}},
{new Object[][]{{}}, new Object[][]{{1, 2}}, new Object[][]{{1, 2}}},
{new Object[][]{{1}}, new Object[][]{{}}, new Object[][]{{1}}},
{new Object[][]{{}}, new Object[][]{{1}}, new Object[][]{{1}}},
{new Object[][]{{EMPTY_ARRAY}}, new Object[][]{{1}}, new Object[][]{{EMPTY_ARRAY, 1}}},
{new Object[][]{{1}, {2}, {3}}, new Object[][]{{4}, {5}, {6}},
new Object[][]{{1,4}, {1,5}, {1,6}, {2, 4}, {2, 5}, {2, 6}, {3, 4}, {3, 5}, {3, 6}}}
};
}

Expand All @@ -93,4 +104,48 @@ public void testProduct(Object[][] dataProvider1, Object[][] dataProvider2, Obje
final Object[][] actual = TestNGUtils.cartesianProduct(dataProvider1, dataProvider2);
assertNestedArraysEqual(actual, expectedResult);
}


@DataProvider
public Object[][] getDifferingNumbersOfProviders() {
final Object[][] p1 = new Object[][]{{1}, {2}};
final Object[][] p2 = new Object[][]{{"a", "b"}};
final Object[][] p3 = new Object[][]{{}};
final Object[][] p4 = new Object[][]{{3}, {4}, {5}};

final Object[][] expected0 = new Object[][]{{}};
final Object[][] expected1 = new Object[][]{{1}, {2}};
final Object[][] expected2 = new Object[][]{{1, "a", "b"}, {2, "a", "b"}};
final Object[][] expected3 = expected2;
final Object[][] expected4 = new Object[][]{
{1, "a", "b", 3},
{1, "a", "b", 4},
{1, "a", "b", 5},
{2, "a", "b", 3},
{2, "a", "b", 4},
{2, "a", "b", 5}
};

return new Object[][]{
{Arrays.asList(), expected0},
{Collections.singletonList(p1), expected1},
{Arrays.asList(p1, p2), expected2},
{Arrays.asList(p1, p2, p3), expected3},
{Arrays.asList(p1, p2, p3, p4), expected4}
};
}

@Test(dataProvider = "getDifferingNumbersOfProviders")
public void testCartesianProductOfManyProviders(List<Object[]> providers, Object[][] expected){
final Object[][] product = TestNGUtils.cartesianProduct(providers.toArray(new Object[][][]{}));
assertNestedArraysEqual(product, expected);
}

@Test
public void testSingleProvider() {
final Object[][] expected = {{1, 2}};
final Object[][] product = TestNGUtils.cartesianProduct(expected);
assertNestedArraysEqual(product, expected);
}

lbergelson marked this conversation as resolved.
Show resolved Hide resolved
}