/** * Transforms the content of the heap into an index. * * <p> * The heap contents are flushed as a result, so is left ready for another use. * </p> * * @return a valid likelihood index. */ private int alleleHeapToIndex() { if (alleleHeap.size() != ploidy) throw new IllegalArgumentException("the sum of allele counts must be equal to the ploidy of the calculator"); if (alleleHeap.peek() >= alleleCount) throw new IllegalArgumentException("invalid allele " + alleleHeap.peek() + " more than the maximum " + (alleleCount - 1)); int result = 0; for (int p = ploidy; p > 0; p--) { final int allele = alleleHeap.remove(); if (allele < 0) throw new IllegalArgumentException("invalid allele " + allele + " must be equal or greater than 0 "); result += alleleFirstGenotypeOffsetByPloidy[p][allele]; } return result; }
@Test(dataProvider = "capacityData", dependsOnMethods = {"testCapacity"}) public void testPeek(final int initialCapacity, final int elementCount) { final IntMaxHeap heap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); int top = rnd.nextInt(); heap.add(top); Assert.assertEquals(heap.peek(),top); for (int i = 1; i < elementCount; i++) { final int v = rnd.nextInt(); if (v > top) top = v; heap.add(v); Assert.assertEquals(heap.peek(),top); } }