Skip to content

Commit

Permalink
Updating tests in SAMRecordUnitTest to explicitly compare values as p…
Browse files Browse the repository at this point in the history
…rimitives (#1696)

* Tests were failing on debian systems due to ambiguity between
  boxed and unboxed number comparisons in SAMRecordUnitTest
  See #1695

* Fix the ambiguity by explictly converting values to the primitive types before comparing

Co-authored-by: Pierre Gruet <[email protected]>
  • Loading branch information
lbergelson and Pierre Gruet authored Dec 18, 2023
1 parent b23c36a commit 1ca889d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/test/java/htsjdk/samtools/SAMRecordUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,21 @@ public void test_getUnsignedIntegerAttribute_valid() {
Assert.assertNull(record.getUnsignedIntegerAttribute(binaryTag));

record.setAttribute("UI", (long) 0L);
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag).longValue());
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag).longValue());

record.setAttribute("UI", BinaryCodec.MAX_UINT);
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag).longValue());
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag).longValue());

final SAMBinaryTagAndValue tv_zero = new SAMBinaryTagAndValue(binaryTag, 0L);
record = new SAMRecord(header){
{
setAttributes(tv_zero);
}
};
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag).longValue());
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag).longValue());

final SAMBinaryTagAndValue tv_max = new SAMBinaryTagAndValue(binaryTag, BinaryCodec.MAX_UINT);
record = new SAMRecord(header){
Expand All @@ -365,8 +365,8 @@ record = new SAMRecord(header){
setAttributes(tv_max);
}
};
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag).longValue());
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag).longValue());
}

/**
Expand All @@ -381,11 +381,11 @@ public void test_getUnsignedIntegerAttribute_valid_alternative() {

record = new SAMRecord(header);
record.setAttribute("UI", 0L);
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(tag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(tag).longValue());

record = new SAMRecord(header);
record.setAttribute("UI", BinaryCodec.MAX_UINT);
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute("UI"));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute("UI").longValue());
}

@Test(expectedExceptions = SAMException.class)
Expand Down Expand Up @@ -464,7 +464,7 @@ public void test_setAttribute_null_removes_tag() {
Assert.assertNull(record.getUnsignedIntegerAttribute(tag));

record.setAttribute(tag, BinaryCodec.MAX_UINT);
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(tag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(tag).longValue());

record.setAttribute(tag, null);
Assert.assertNull(record.getUnsignedIntegerAttribute(tag));
Expand Down Expand Up @@ -878,7 +878,7 @@ public void testSetHeaderStrictValidNewHeader() {

// force re-resolution of the reference name against the new header
sam.setHeaderStrict(newHeader);
Assert.assertEquals(sam.getReferenceIndex(), 0);
Assert.assertEquals(sam.getReferenceIndex().intValue(), 0);
}

@Test(expectedExceptions=IllegalArgumentException.class)
Expand All @@ -887,7 +887,7 @@ public void testSetHeaderStrictInvalidReference() {
final SAMFileHeader samHeader = sam.getHeader();

sam.setReferenceName("unresolvable");
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getReferenceIndex());
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getReferenceIndex().intValue());

// throw on force re-resolution of the unresolvable reference name
sam.setHeaderStrict(samHeader);
Expand All @@ -899,7 +899,7 @@ public void testSetHeaderStrictInvalidMateReference() {
final SAMFileHeader samHeader = sam.getHeader();

sam.setMateReferenceName("unresolvable");
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getMateReferenceIndex());
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getMateReferenceIndex().intValue());

// throw on force re-resolution of the unresolvable mate reference name
sam.setHeaderStrict(samHeader);
Expand All @@ -921,7 +921,7 @@ public void testResolveIndexResolvable() {
final SAMRecord sam = createTestRecordHelper();
final SAMFileHeader samHeader = sam.getHeader();
final String contigName = sam.getContig();
Assert.assertEquals(SAMRecord.resolveIndexFromName(contigName, samHeader, true), samHeader.getSequenceIndex(contigName));
Assert.assertEquals(SAMRecord.resolveIndexFromName(contigName, samHeader, true).intValue(), samHeader.getSequenceIndex(contigName));
}

@Test(expectedExceptions=IllegalStateException.class)
Expand All @@ -945,7 +945,7 @@ public void testResolveIndexUnresolvableNotStrict() {
public void testResolveIndexNoAlignment() {
final SAMFileHeader samHeader = new SAMFileHeader();
Assert.assertEquals(SAMRecord.resolveIndexFromName(
SAMRecord.NO_ALIGNMENT_REFERENCE_NAME, samHeader, true), SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
SAMRecord.NO_ALIGNMENT_REFERENCE_NAME, samHeader, true).intValue(), SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
}

@Test(expectedExceptions=IllegalStateException.class)
Expand Down

0 comments on commit 1ca889d

Please sign in to comment.