/** * Test that the contents of an allele-list are the ones expected. * * <p> * * <p>This method perform various consistency check involving all the {@link * org.broadinstitute.gatk.utils.genotyper.AlleleList} interface methods. Therefore calling this * method is equivalent to a thorough check of the {@link * org.broadinstitute.gatk.utils.genotyper.AlleleList} aspect of the {@code actual} argument. * * @param actual the sample-list to assess. * @param expected the expected sample-list. * @throws IllegalArgumentException if {@code expected} is {@code null} or contains {@code null}s * which is an indication of an bug in the testing code. * @throws RuntimeException if there is some testing assertion exception which is an indication of * an actual bug the code that is been tested. */ public static <A extends Allele> void assertAlleleList( final AlleleList<A> actual, final List<A> expected) { if (expected == null) throw new IllegalArgumentException("the expected list cannot be null"); final Set<A> expectedAlleleSet = new HashSet<>(expected.size()); Assert.assertNotNull(actual); Assert.assertEquals(actual.alleleCount(), expected.size()); for (int i = 0; i < expected.size(); i++) { final A expectedAllele = expected.get(i); if (expectedAllele == null) throw new IllegalArgumentException("the expected sample cannot be null"); if (expectedAllele.equals(NEVER_USE_ALLELE)) throw new IllegalArgumentException("you cannot use the forbidden sample name"); if (expectedAlleleSet.contains(expected.get(i))) throw new IllegalArgumentException( "repeated allele in the expected list, this is a test bug"); final A actualAllele = actual.alleleAt(i); Assert.assertNotNull(actualAllele, "allele cannot be null"); Assert.assertFalse( expectedAlleleSet.contains(actualAllele), "repeated allele: " + actualAllele); Assert.assertEquals(actualAllele, expectedAllele, "wrong allele order; index = " + i); Assert.assertEquals(actual.alleleIndex(actualAllele), i, "allele index mismatch"); expectedAlleleSet.add(actualAllele); } Assert.assertEquals(actual.alleleIndex((A) NEVER_USE_ALLELE), -1); }
/** * Generate testing alleles. * * <p>Basically all are random alleles given the maximum allele length. * * <p>So with a low max-allele-length and high allele-count you can force repeats. * * @param alleleCount number of alleles to generate. * @param maxAlleleLength the maximum length of the allele in bases. * @param skipIfRepeats throw an test-skip exception {@link SkipException} if the resulting * allele-list has repeats, thus is size is less than {@code alleleCount} * @throws RuntimeException if {@code alleleCount} is negative or {@code maxAlleleLength} is less * than 1. * @return never {@code null}. */ static AlleleList<Allele> alleleList( final int alleleCount, final int maxAlleleLength, final boolean skipIfRepeats) { final Allele[] alleles = AlleleListUnitTester.generateRandomAlleles(alleleCount, maxAlleleLength); if (alleleCount > 0) alleles[0] = Allele.create(alleles[0].getBases(), true); final AlleleList<Allele> alleleList = new IndexedAlleleList<>(alleles); if (skipIfRepeats && alleleList.alleleCount() != alleles.length) throw new SkipException("repeated alleles, should be infrequent"); return alleleList; }