/** * Creates a new calculator providing its ploidy and number of genotyping alleles. */ protected GenotypeLikelihoodCalculator(final int ploidy, final int alleleCount, final int[][] alleleFirstGenotypeOffsetByPloidy, final GenotypeAlleleCounts[][] genotypeTableByPloidy, final double[] ploidyLog10) { this.alleleFirstGenotypeOffsetByPloidy = alleleFirstGenotypeOffsetByPloidy; genotypeAlleleCounts = genotypeTableByPloidy[ploidy]; this.alleleCount = alleleCount; this.ploidy = ploidy; genotypeCount = this.alleleFirstGenotypeOffsetByPloidy[ploidy][alleleCount]; alleleHeap = new IntMaxHeap(ploidy); readLikelihoodsByGenotypeIndex = new double[genotypeCount][]; this.ploidyLog10 = ploidyLog10; // The number of possible components is limited by distinct allele count and ploidy. maximumDistinctAllelesInGenotype = Math.min(ploidy, alleleCount); genotypeAllelesAndCounts = new int[maximumDistinctAllelesInGenotype*2]; }
@Test(dataProvider = "capacityData") public void testCapacity(final int initialCapacity, final int elementCount) { final IntMaxHeap heap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); for (int i = 0; i < elementCount; i++) { final int v = rnd.nextInt(); heap.add(v); } }
@Test(dataProvider = "capacityData", dependsOnMethods = {"testEmptynessAndSize"}) public void testRemove(final int initialCapacity, final int elementCount) { final IntMaxHeap heap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); final List<Integer> values = new ArrayList<>(elementCount); for (int i = 0; i < elementCount; i++) { final int v = rnd.nextInt(); values.add(v); heap.add(v); } Collections.sort(values, Collections.reverseOrder()); for (int i = 0; i < elementCount; i++) { Assert.assertEquals(heap.remove(),(int)values.get(i), "element-count = " + elementCount + ", initial-capacity = " + initialCapacity); Assert.assertEquals(heap.size(),elementCount - i - 1); } }
@Test(dataProvider = "capacityData", dependsOnMethods = {"testEmptynessAndSize"}) public void testClear(final int initialCapacity, final int elementCount) { final IntMaxHeap heap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); for (int i = 0; i < elementCount; i++) { final int v = rnd.nextInt(); heap.add(v); } heap.clear(); Assert.assertEquals(heap.size(),0); Assert.assertTrue(heap.isEmpty()); }
@Test(dataProvider = "capacityData",dependsOnMethods = {"testCapacity"}) public void testEmptynessAndSize(final int initialCapacity, final int elementCount) { final IntMaxHeap heap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); Assert.assertEquals(heap.size(),0); Assert.assertTrue(heap.isEmpty()); for (int i = 0; i < elementCount; i++) { final int v = rnd.nextInt(); heap.add(v); Assert.assertEquals(heap.size(),i+1); Assert.assertFalse(heap.isEmpty()); } }
@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); } }
@Test(dataProvider = "capacityData", dependsOnMethods = {"testCapacity"}) public void testAddArray(final int initialCapacity, final int elementCount) { final IntMaxHeap addHeap = new IntMaxHeap(initialCapacity); final IntMaxHeap arrayAddHeap = new IntMaxHeap(initialCapacity); final Random rnd = Utils.getRandomGenerator(); final int[] values = new int[elementCount]; for (int i = 0; i < elementCount; i++) { final int v = rnd.nextInt(); values[i] = v; addHeap.add(v); } arrayAddHeap.add(values); Assert.assertEquals(arrayAddHeap.size(),addHeap.size()); while (!arrayAddHeap.isEmpty()) Assert.assertEquals(arrayAddHeap.remove(),addHeap.remove()); }