@Test public void testAppend () throws IOException {

    List<PairedHit> orighits = new ArrayList<PairedHit>();
    List<PairedHit> newhits = new ArrayList<PairedHit>();
    int len = 1000;
    for (int i = 0; i < len; i++) {
        orighits.add(new PairedHit(isLeft ? chrom : (int)(Math.random() * 1000),
                               (int)(Math.random() * 100000000),
                               i % 3 == 1,
                               (short)(Math.random()*100+1),
                               isLeft ? (int)(Math.random() * 1000) : chrom,
                               (int)(Math.random() * 100000000),
                               i % 3 == 1,
                               (short)(Math.random()*100+1),
                               (float)Math.random()));
    }        
    for (int i = 0; i < len; i++) {
        newhits.add(new PairedHit(isLeft ? chrom : (int)(Math.random() * 1000),
                               (int)(Math.random() * 100000000),
                               i % 3 == 1,
                               (short)(Math.random()*100+1),
                               isLeft ? (int)(Math.random() * 1000) : chrom,
                               (int)(Math.random() * 100000000),
                               i % 3 == 1,
                               (short)(Math.random()*100+1),
                               (float)Math.random()));
    }      
    Collections.sort(orighits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator());
    Collections.sort(newhits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator());
    PairedHits.writePairedHits(orighits, prefix, chrom, isLeft);
    hitsfile = new PairedHits(prefix,chrom,isLeft);
    hitsfile.appendPairedHits(newhits,prefix + "appended", chrom, isLeft);
    hitsfile = new PairedHits(prefix + "appended",chrom,isLeft);
    assertEquals(hitsfile.isLeft(), isLeft);
    ArrayList<PairedHit> allhits = new ArrayList<PairedHit>();
    allhits.addAll(orighits);
    allhits.addAll(newhits);
    Collections.sort(allhits, isLeft ? new PairedHitLeftComparator() : new PairedHitRightComparator());
    IntBP positions = hitsfile.getPositionsBuffer();
    IntBP las = hitsfile.getLASBuffer();
    FloatBP weights = hitsfile.getWeightsBuffer();
    IntBP otherchrom = hitsfile.getChromsBuffer();
    IntBP otherpos = hitsfile.getOtherPosBuffer();
    for (int i = 0; i < allhits.size(); i++) {
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)), 
                     allhits.get(i).leftChrom, isLeft ? chrom : otherchrom.get(i));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).leftPos, isLeft ? positions.get(i) : otherpos.get(i));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).leftStrand, isLeft ? Hits.getStrandOne(las.get(i)) : Hits.getStrandTwo(las.get(i)));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).leftLength, isLeft ? Hits.getLengthOne(las.get(i)) : Hits.getLengthTwo(las.get(i)));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).rightChrom, !isLeft ? chrom : otherchrom.get(i));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).rightPos, !isLeft ? positions.get(i) : otherpos.get(i));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).rightStrand, !isLeft ? Hits.getStrandOne(las.get(i)) : Hits.getStrandTwo(las.get(i)));
        assertEquals(String.format("Hit %d, %s",i,allhits.get(i)),
                     allhits.get(i).rightLength, !isLeft ? Hits.getLengthOne(las.get(i)) : Hits.getLengthTwo(las.get(i)));
        
        assertTrue(String.format("Hit %d, %s",i,allhits.get(i)),
                   Math.abs(allhits.get(i).weight - weights.get(i)) < .00001);                               
    }
}