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

Relax Beta Encoding requirement to allow 0 bits #1233

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class BetaIntegerEncoding extends CRAMEncoding<Integer> {
public BetaIntegerEncoding(final int offset, final int bitsPerValue) {
super(EncodingID.BETA);

if (bitsPerValue <= 0) {
throw new IllegalArgumentException("Number of bits per value must be positive");
if (bitsPerValue < 0) {
throw new IllegalArgumentException("Number of bits per value must not be negative");
} else if (bitsPerValue > 32) {
throw new IllegalArgumentException("Number of bits per value must be 32 or lower");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public Object[][] basicTestData() {
return new Object[][] {
{8, -100, new int[]{100, 101, 102, (1<<8) + 98, (1<<8) + 99}},
{4, 10015, new int[]{-10015, -10014, -10001, -10000}},
{0, 0, new int[]{0, 0, 0}},
{0, 100, new int[]{-100, -100}},
};
}

Expand All @@ -62,6 +64,7 @@ public Object[][] basicTestNoOffsetData() {
return new Object[][] {
{8, new int[]{0, 1, 2, 100, (1 << 8) - 2, (1 << 8) - 1}},
{16, new int[]{0, 1, 255, (1 << 16) - 2, (1 << 16) - 1}},
{0, new int[]{0, 0, 0}},
};
}

Expand All @@ -77,13 +80,15 @@ public Object[][] overflowData() {
// tuples of bitsPerValue and offsets + values which are too big to store
return new Object[][] {
// first with zero offset
{0, 0, 1},
{1, 0, (1 << 1)},
{2, 0, (1 << 2)},
{4, 0, (1 << 4)},
{8, 0, (1 << 8)},
{16, 0, (1 << 16)},

// adding offset of 1 will put it over
{0, 1, 0},
{1, 1, (1 << 1) - 1},
{2, 1, (1 << 2) - 1},
{4, 1, (1 << 4) - 1},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class BetaIntegerEncodingTest extends HtsjdkTest {
public Object[][] testData() {
return new Object[][] {
// positive values below the ITF8 single-byte limit (128) are encoded as-is
{0, 0, new byte[] { 0, 0 }},
{0, 8, new byte[] { 0, 8 }},
{127, 32, new byte[] { 127, 32 }},

Expand All @@ -32,12 +33,11 @@ public void paramsTest(final int offset, final int bitLength, final byte[] expec
}


// sanity checks for bitsPerValue. Must be > 0 and <= 32
// sanity checks for bitsPerValue. Must be between 0 and 32, inclusive

@DataProvider(name = "bitsPerValue")
public Object[][] bitsPerValueData() {
return new Object[][] {
{0},
{-1},
{33}
};
Expand Down