public static void addComplexGenotypesTest() {
    final List<Allele> allAlleles =
        Arrays.asList(
            Allele.create("A", true), Allele.create("C", false), Allele.create("G", false));

    for (int nAlleles : Arrays.asList(2, 3)) {
      for (int highestPloidy : Arrays.asList(1, 2, 3)) {
        // site alleles
        final List<Allele> siteAlleles = allAlleles.subList(0, nAlleles);

        // possible alleles for genotypes
        final List<Allele> possibleGenotypeAlleles = new ArrayList<Allele>(siteAlleles);
        possibleGenotypeAlleles.add(Allele.NO_CALL);

        // there are n^ploidy possible genotypes
        final List<List<Allele>> possibleGenotypes =
            makeAllGenotypes(possibleGenotypeAlleles, highestPloidy);
        final int nPossibleGenotypes = possibleGenotypes.size();

        VariantContextBuilder vb = new VariantContextBuilder("unittest", "1", 1, 1, siteAlleles);

        // first test -- create n copies of each genotype
        for (int i = 0; i < nPossibleGenotypes; i++) {
          final List<Genotype> samples = new ArrayList<Genotype>(3);
          samples.add(GenotypeBuilder.create("sample" + i, possibleGenotypes.get(i)));
          add(vb.genotypes(samples));
        }

        // second test -- create one sample with each genotype
        {
          final List<Genotype> samples = new ArrayList<Genotype>(nPossibleGenotypes);
          for (int i = 0; i < nPossibleGenotypes; i++) {
            samples.add(GenotypeBuilder.create("sample" + i, possibleGenotypes.get(i)));
          }
          add(vb.genotypes(samples));
        }

        // test mixed ploidy
        for (int i = 0; i < nPossibleGenotypes; i++) {
          for (int ploidy = 1; ploidy < highestPloidy; ploidy++) {
            final List<Genotype> samples = new ArrayList<Genotype>(highestPloidy);
            final List<Allele> genotype = possibleGenotypes.get(i).subList(0, ploidy);
            samples.add(GenotypeBuilder.create("sample" + i, genotype));
            add(vb.genotypes(samples));
          }
        }
      }
    }
  }
 private static Genotype attr(
     final String name, final Allele ref, final String key, final Object... value) {
   if (value.length == 0) return GenotypeBuilder.create(name, Arrays.asList(ref, ref));
   else {
     final Object toAdd = value.length == 1 ? value[0] : Arrays.asList(value);
     return new GenotypeBuilder(name, Arrays.asList(ref, ref)).attribute(key, toAdd).make();
   }
 }
  private static void addGenotypes(final VariantContext site) {
    // test ref/ref
    final Allele ref = site.getReference();
    final Allele alt1 = site.getNAlleles() > 1 ? site.getAlternateAllele(0) : null;
    final Genotype homRef = GenotypeBuilder.create("homRef", Arrays.asList(ref, ref));
    addGenotypeTests(site, homRef);

    if (alt1 != null) {
      final Genotype het = GenotypeBuilder.create("het", Arrays.asList(ref, alt1));
      final Genotype homVar = GenotypeBuilder.create("homVar", Arrays.asList(alt1, alt1));
      addGenotypeTests(site, homRef, het);
      addGenotypeTests(site, homRef, het, homVar);

      // test no GT at all
      addGenotypeTests(
          site, new GenotypeBuilder("noGT", new ArrayList<Allele>(0)).attribute("INT1", 10).make());

      final List<Allele> noCall = Arrays.asList(Allele.NO_CALL, Allele.NO_CALL);

      // ploidy
      if (ENABLE_PLOIDY_TESTS) {
        addGenotypeTests(
            site,
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("hap", Arrays.asList(ref)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("noCall", noCall),
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("hap", Arrays.asList(ref)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("noCall", noCall),
            GenotypeBuilder.create("noCall2", noCall),
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("hap", Arrays.asList(ref)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("noCall", noCall),
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("noCall", noCall),
            GenotypeBuilder.create("noCall2", noCall),
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("nocall", noCall),
            GenotypeBuilder.create("dip", Arrays.asList(ref, alt1)),
            GenotypeBuilder.create("tet", Arrays.asList(ref, alt1, alt1)));
      }

      //
      //
      // TESTING PHASE
      //
      //
      final Genotype gUnphased = new GenotypeBuilder("gUnphased", Arrays.asList(ref, alt1)).make();
      final Genotype gPhased =
          new GenotypeBuilder("gPhased", Arrays.asList(ref, alt1)).phased(true).make();
      final Genotype gPhased2 =
          new GenotypeBuilder("gPhased2", Arrays.asList(alt1, alt1)).phased(true).make();
      final Genotype gPhased3 =
          new GenotypeBuilder("gPhased3", Arrays.asList(ref, ref)).phased(true).make();
      final Genotype haploidNoPhase =
          new GenotypeBuilder("haploidNoPhase", Arrays.asList(ref)).make();
      addGenotypeTests(site, gUnphased, gPhased);
      addGenotypeTests(site, gUnphased, gPhased2);
      addGenotypeTests(site, gUnphased, gPhased3);
      addGenotypeTests(site, gPhased, gPhased2);
      addGenotypeTests(site, gPhased, gPhased3);
      addGenotypeTests(site, gPhased2, gPhased3);
      addGenotypeTests(site, haploidNoPhase, gPhased);
      addGenotypeTests(site, haploidNoPhase, gPhased2);
      addGenotypeTests(site, haploidNoPhase, gPhased3);
      addGenotypeTests(site, haploidNoPhase, gPhased, gPhased2);
      addGenotypeTests(site, haploidNoPhase, gPhased, gPhased3);
      addGenotypeTests(site, haploidNoPhase, gPhased2, gPhased3);
      addGenotypeTests(site, haploidNoPhase, gPhased, gPhased2, gPhased3);

      final Genotype gUnphasedTet =
          new GenotypeBuilder("gUnphasedTet", Arrays.asList(ref, alt1, ref, alt1)).make();
      final Genotype gPhasedTet =
          new GenotypeBuilder("gPhasedTet", Arrays.asList(ref, alt1, alt1, alt1))
              .phased(true)
              .make();
      addGenotypeTests(site, gUnphasedTet, gPhasedTet);
    }

    if (ENABLE_PL_TESTS) {
      if (site.getNAlleles() == 2) {
        // testing PLs
        addGenotypeTests(
            site,
            GenotypeBuilder.create("g1", Arrays.asList(ref, ref), new double[] {0, -1, -2}),
            GenotypeBuilder.create("g2", Arrays.asList(ref, ref), new double[] {0, -2, -3}));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("g1", Arrays.asList(ref, ref), new double[] {-1, 0, -2}),
            GenotypeBuilder.create("g2", Arrays.asList(ref, ref), new double[] {0, -2, -3}));

        addGenotypeTests(
            site,
            GenotypeBuilder.create("g1", Arrays.asList(ref, ref), new double[] {-1, 0, -2}),
            GenotypeBuilder.create("g2", Arrays.asList(ref, ref), new double[] {0, -2000, -1000}));

        addGenotypeTests(
            site, // missing PLs
            GenotypeBuilder.create("g1", Arrays.asList(ref, ref), new double[] {-1, 0, -2}),
            GenotypeBuilder.create("g2", Arrays.asList(ref, ref)));
      } else if (site.getNAlleles() == 3) {
        // testing PLs
        addGenotypeTests(
            site,
            GenotypeBuilder.create(
                "g1", Arrays.asList(ref, ref), new double[] {0, -1, -2, -3, -4, -5}),
            GenotypeBuilder.create(
                "g2", Arrays.asList(ref, ref), new double[] {0, -2, -3, -4, -5, -6}));
      }
    }

    // test attributes
    addGenotypeTests(site, attr("g1", ref, "INT1", 1), attr("g2", ref, "INT1", 2));
    addGenotypeTests(site, attr("g1", ref, "INT1", 1), attr("g2", ref, "INT1"));
    addGenotypeTests(site, attr("g1", ref, "INT3", 1, 2, 3), attr("g2", ref, "INT3", 4, 5, 6));
    addGenotypeTests(site, attr("g1", ref, "INT3", 1, 2, 3), attr("g2", ref, "INT3"));

    addGenotypeTests(
        site, attr("g1", ref, "INT20", TWENTY_INTS), attr("g2", ref, "INT20", TWENTY_INTS));

    if (ENABLE_VARARRAY_TESTS) {
      addGenotypeTests(
          site,
          attr("g1", ref, "INT.VAR", 1, 2, 3),
          attr("g2", ref, "INT.VAR", 4, 5),
          attr("g3", ref, "INT.VAR", 6));
      addGenotypeTests(
          site,
          attr("g1", ref, "INT.VAR", 1, 2, 3),
          attr("g2", ref, "INT.VAR"),
          attr("g3", ref, "INT.VAR", 5));
    }

    addGenotypeTests(site, attr("g1", ref, "FLOAT1", 1.0), attr("g2", ref, "FLOAT1", 2.0));
    addGenotypeTests(site, attr("g1", ref, "FLOAT1", 1.0), attr("g2", ref, "FLOAT1"));
    addGenotypeTests(
        site, attr("g1", ref, "FLOAT3", 1.0, 2.0, 3.0), attr("g2", ref, "FLOAT3", 4.0, 5.0, 6.0));
    addGenotypeTests(site, attr("g1", ref, "FLOAT3", 1.0, 2.0, 3.0), attr("g2", ref, "FLOAT3"));

    if (ENABLE_VARIABLE_LENGTH_GENOTYPE_STRING_TESTS) {
      //
      //
      // TESTING MULTIPLE SIZED LISTS IN THE GENOTYPE FIELD
      //
      //
      addGenotypeTests(
          site,
          attr("g1", ref, "GS", Arrays.asList("S1", "S2")),
          attr("g2", ref, "GS", Arrays.asList("S3", "S4")));

      addGenotypeTests(
          site, // g1 is missing the string, and g2 is missing FLOAT1
          attr("g1", ref, "FLOAT1", 1.0),
          attr("g2", ref, "GS", Arrays.asList("S3", "S4")));

      // variable sized lists
      addGenotypeTests(
          site, attr("g1", ref, "GV", "S1"), attr("g2", ref, "GV", Arrays.asList("S3", "S4")));

      addGenotypeTests(
          site,
          attr("g1", ref, "GV", Arrays.asList("S1", "S2")),
          attr("g2", ref, "GV", Arrays.asList("S3", "S4", "S5")));

      addGenotypeTests(
          site, // missing value in varlist of string
          attr("g1", ref, "FLOAT1", 1.0),
          attr("g2", ref, "GV", Arrays.asList("S3", "S4", "S5")));
    }

    //
    //
    // TESTING GENOTYPE FILTERS
    //
    //
    addGenotypeTests(
        site,
        new GenotypeBuilder("g1-x", Arrays.asList(ref, ref)).filters("X").make(),
        new GenotypeBuilder("g2-x", Arrays.asList(ref, ref)).filters("X").make());
    addGenotypeTests(
        site,
        new GenotypeBuilder("g1-unft", Arrays.asList(ref, ref)).unfiltered().make(),
        new GenotypeBuilder("g2-x", Arrays.asList(ref, ref)).filters("X").make());
    addGenotypeTests(
        site,
        new GenotypeBuilder("g1-unft", Arrays.asList(ref, ref)).unfiltered().make(),
        new GenotypeBuilder("g2-xy", Arrays.asList(ref, ref)).filters("X", "Y").make());
    addGenotypeTests(
        site,
        new GenotypeBuilder("g1-unft", Arrays.asList(ref, ref)).unfiltered().make(),
        new GenotypeBuilder("g2-x", Arrays.asList(ref, ref)).filters("X").make(),
        new GenotypeBuilder("g3-xy", Arrays.asList(ref, ref)).filters("X", "Y").make());
  }
 private Genotype makeG(String sample, Allele a1, Allele a2) {
   return GenotypeBuilder.create(sample, Arrays.asList(a1, a2));
 }