method2testcases
stringlengths 118
3.08k
|
---|
### Question:
ProteinExtension extends ProteinChange { public static ProteinExtension buildWithoutTerminal(boolean onlyPredicted, String wtAA, int pos, String targetAA) { return new ProteinExtension(onlyPredicted, ProteinPointLocation.build(wtAA, pos), targetAA, LEN_NO_TER); } ProteinExtension(boolean onlyPredicted, ProteinPointLocation position, String targetAA, int shift); static ProteinExtension build(boolean onlyPredicted, String wtAA, int pos, String targetAA, int shift); static ProteinExtension build(boolean onlyPredicted, ProteinPointLocation position, String targetAA,
int shift); static ProteinExtension buildWithoutTerminal(boolean onlyPredicted, String wtAA, int pos, String targetAA); static ProteinExtension buildWithoutTerminal(boolean onlyPredicted, ProteinPointLocation position,
String targetAA); ProteinPointLocation getPosition(); String getTargetAA(); int getShift(); boolean isNoTerminalExtension(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); static final int LEN_NO_TER; }### Answer:
@Test public void testBuildNoTerExtension() { Assert.assertEquals(noTerExtension, ProteinExtension.buildWithoutTerminal(false, position, "T")); } |
### Question:
ProteinRange implements ConvertibleToHGVSString { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ProteinRange other = (ProteinRange) obj; if (first == null) { if (other.first != null) return false; } else if (!first.equals(other.first)) return false; if (last == null) { if (other.last != null) return false; } else if (!last.equals(other.last)) return false; return true; } ProteinRange(ProteinPointLocation first, ProteinPointLocation last); static ProteinRange build(String firstAA, int first, String lastAA, int last); static ProteinRange buildWithOffset(String firstAA, int first, int firstOffset, String lastAA, int last,
int lastOffset); static ProteinRange buildDownstreamOfTerminal(String firstAA, int first, String lastAA, int last); ProteinPointLocation getFirst(); ProteinPointLocation getLast(); int length(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testEquals() { Assert.assertEquals(firstRange, firstRange2); Assert.assertNotEquals(secondRange, firstRange); } |
### Question:
ProteinRange implements ConvertibleToHGVSString { @Override public String toHGVSString() { return toHGVSString(AminoAcidCode.THREE_LETTER); } ProteinRange(ProteinPointLocation first, ProteinPointLocation last); static ProteinRange build(String firstAA, int first, String lastAA, int last); static ProteinRange buildWithOffset(String firstAA, int first, int firstOffset, String lastAA, int last,
int lastOffset); static ProteinRange buildDownstreamOfTerminal(String firstAA, int first, String lastAA, int last); ProteinPointLocation getFirst(); ProteinPointLocation getLast(); int length(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToHGVSStringWithOffset() { Assert.assertEquals("Gly126-1_Thr302-1", offsetRange.toHGVSString()); }
@Test public void testToHGVSStringDownstreamOfTerminal() { Assert.assertEquals("Gly*126_Thr*302", downstreamOfTerminalRange.toHGVSString()); } |
### Question:
PedPerson { public boolean isFounder() { return ("0".equals(father) && "0".equals(mother)); } PedPerson(String pedigree, String name, String father, String mother, Sex sex, Disease disease,
Collection<String> extraFields); PedPerson(String pedigree, String name, String father, String mother, Sex sex, Disease disease); String getPedigree(); String getName(); String getFather(); String getMother(); Sex getSex(); Disease getDisease(); ImmutableList<String> getExtraFields(); boolean isFounder(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testIsFounderTrue() { PedPerson person = new PedPerson("fam", "name", "0", "0", Sex.MALE, Disease.AFFECTED); Assert.assertTrue(person.isFounder()); }
@Test public void testIsFounderFalse() { PedPerson person = new PedPerson("fam", "name", "father", "0", Sex.MALE, Disease.AFFECTED); Assert.assertFalse(person.isFounder()); } |
### Question:
PedFileWriter { public void write(PedFileContents contents) throws IOException { FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream stream = new BufferedOutputStream(fos); write(contents, stream); stream.close(); fos.close(); } PedFileWriter(File file); void write(PedFileContents contents); static void write(PedFileContents contents, OutputStream stream); }### Answer:
@Test public void testWrite() throws IOException { ImmutableList.Builder<PedPerson> individuals = new ImmutableList.Builder<PedPerson>(); individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); PedFileContents pedFileContents = new PedFileContents(new ImmutableList.Builder<String>().build(), individuals.build()); PedFileWriter writer = new PedFileWriter(tmpFile); writer.write(pedFileContents); String fileContents = Files.asCharSource(tmpFile, Charsets.UTF_8).read(); StringBuilder expectedContents = new StringBuilder(); expectedContents.append("#PEDIGREE\tNAME\tFATHER\tMOTHER\tSEX\tDISEASE\n"); expectedContents.append("fam\tfather\t0\t0\t1\t0\n"); expectedContents.append("fam\tmother\t0\t0\t2\t0\n"); expectedContents.append("fam\tson\tfather\tmother\t1\t0\n"); expectedContents.append("fam\tdaughter\tfather\tmother\t2\t0\n"); Assert.assertEquals(expectedContents.toString(), fileContents); } |
### Question:
PedigreeQueryDecorator { public boolean isParentOfAffected(Person person) { for (Person member : pedigree.getMembers()) if (member.getFather() == person || member.getMother() == person) return true; return false; } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testIsParentOfAffected() { Assert.assertTrue(decorator.isParentOfAffected(pedigree.getMembers().get(0))); Assert.assertTrue(decorator.isParentOfAffected(pedigree.getMembers().get(1))); Assert.assertFalse(decorator.isParentOfAffected(pedigree.getMembers().get(2))); Assert.assertFalse(decorator.isParentOfAffected(pedigree.getMembers().get(3))); } |
### Question:
PedigreeQueryDecorator { public ImmutableSet<String> getUnaffectedNames() { ImmutableSet.Builder<String> resultNames = new ImmutableSet.Builder<String>(); for (Person member : pedigree.getMembers()) if (member.getDisease() == Disease.UNAFFECTED) resultNames.add(member.getName()); return resultNames.build(); } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetUnaffectedNames() { Assert.assertEquals(ImmutableSet.of("father"), decorator.getUnaffectedNames()); } |
### Question:
PedigreeQueryDecorator { public ImmutableSet<String> getParentNames() { ImmutableSet.Builder<String> parentNames = new ImmutableSet.Builder<String>(); for (Person member : pedigree.getMembers()) { if (member.getFather() != null) parentNames.add(member.getFather().getName()); if (member.getMother() != null) parentNames.add(member.getMother().getName()); } return parentNames.build(); } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetParentNames() { Assert.assertEquals(ImmutableSet.of("father", "mother"), decorator.getParentNames()); } |
### Question:
PedigreeQueryDecorator { public ImmutableList<Person> getParents() { ImmutableSet<String> parentNames = getParentNames(); ImmutableList.Builder<Person> builder = new ImmutableList.Builder<Person>(); for (Person member : pedigree.getMembers()) if (parentNames.contains(member.getName())) builder.add(member); return builder.build(); } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetParents() { Assert.assertEquals(ImmutableList.of(pedigree.getMembers().get(0), pedigree.getMembers().get(1)), decorator.getParents()); } |
### Question:
PedigreeQueryDecorator { public int getNumberOfParents() { HashSet<String> parentNames = new HashSet<String>(); for (Person member : pedigree.getMembers()) { if (member.getFather() != null) parentNames.add(member.getFather().getName()); if (member.getMother() != null) parentNames.add(member.getMother().getName()); } return parentNames.size(); } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetNumberOfParents() { Assert.assertEquals(2, decorator.getNumberOfParents()); } |
### Question:
ProteinPointLocation implements ConvertibleToHGVSString { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ProteinPointLocation other = (ProteinPointLocation) obj; if (aa == null) { if (other.aa != null) return false; } else if (!aa.equals(other.aa)) return false; if (downstreamOfTerminal != other.downstreamOfTerminal) return false; if (offset != other.offset) return false; if (pos != other.pos) return false; return true; } ProteinPointLocation(String aa, int pos, int offset, boolean downstreamOfTerminal); static ProteinPointLocation build(String aa, int pos); static ProteinPointLocation buildWithOffset(String aa, int pos, int offset); static ProteinPointLocation buildDownstreamOfTerminal(String aa, int pos); int getPos(); String getAA(); int getOffset(); boolean isDownstreamOfTerminal(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testEquals() { Assert.assertTrue(location1.equals(location2)); Assert.assertTrue(location2.equals(location1)); Assert.assertFalse(location1.equals(location3)); Assert.assertFalse(location3.equals(location1)); } |
### Question:
PedigreeQueryDecorator { public int getNumberOfAffecteds() { int result = 0; for (Person member : pedigree.getMembers()) if (member.getDisease() == Disease.AFFECTED) result += 1; return result; } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetNumberOfAffecteds() { Assert.assertEquals(1, decorator.getNumberOfAffecteds()); } |
### Question:
PedigreeQueryDecorator { public int getNumberOfUnaffecteds() { int result = 0; for (Person member : pedigree.getMembers()) if (member.getDisease() == Disease.UNAFFECTED) result += 1; return result; } PedigreeQueryDecorator(Pedigree pedigree); Pedigree getPedigree(); boolean isParentOfAffected(Person person); ImmutableSet<String> getUnaffectedNames(); ImmutableSet<String> getParentNames(); ImmutableSet<String> getAffectedFemaleParentNames(); ImmutableSet<String> getAffectedMaleParentNames(); ImmutableList<Person> getParents(); int getNumberOfParents(); int getNumberOfAffecteds(); int getNumberOfUnaffecteds(); ImmutableMap<Person, ImmutableList<Person>> buildSiblings(); }### Answer:
@Test public void testGetNumberOfUnaffecteds() { Assert.assertEquals(1, decorator.getNumberOfUnaffecteds()); } |
### Question:
Person { public boolean isFounder() { return (father == null && mother == null); } Person(String name, Person father, Person mother, Sex sex, Disease disease, Collection<String> extraFields); Person(String name, Person father, Person mother, Sex sex, Disease disease); Person(PedPerson pedPerson, PedFileContents pedFileContents, HashMap<String, Person> existing); String getName(); Person getFather(); Person getMother(); Sex getSex(); Disease getDisease(); ImmutableList<String> getExtraFields(); boolean isFounder(); boolean isMale(); boolean isFemale(); boolean isAffected(); boolean isUnaffected(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testIsFounderTrue() { Person index = new Person("name", null, null, Sex.MALE, Disease.AFFECTED); Assert.assertTrue(index.isFounder()); }
@Test public void testIsFounderFalse() { Person father = new Person("father", null, null, Sex.MALE, Disease.AFFECTED); Person index = new Person("name", father, null, Sex.MALE, Disease.AFFECTED); Assert.assertFalse(index.isFounder()); } |
### Question:
GenotypeList { public boolean namesEqual(Pedigree pedigree) { return (pedigree.getNames().equals(names)); } GenotypeList(String geneID, List<String> names, boolean isXChromosomal,
ImmutableList<ImmutableList<Genotype>> calls); String getGeneName(); ImmutableList<String> getNames(); boolean isXChromosomal(); ImmutableList<ImmutableList<Genotype>> getCalls(); boolean namesEqual(Pedigree pedigree); @Override String toString(); }### Answer:
@Test public void testIsNamesEqual() { Assert.assertTrue(list.namesEqual(pedigree1)); Assert.assertFalse(list.namesEqual(pedigree2)); } |
### Question:
PedFileReader { public PedFileContents read() throws IOException, PedParseException { return read(new FileInputStream(file)); } PedFileReader(File file); PedFileContents read(); static PedFileContents read(InputStream stream); }### Answer:
@Test public void testParseWithHeader() throws PedParseException, IOException { PedFileReader reader = new PedFileReader(this.tmpFileWithHeader); PedFileContents pedFileContents = reader.read(); Assert.assertEquals(pedFileContents.getExtraColumnHeaders().size(), 0); ImmutableList.Builder<PedPerson> individuals = new ImmutableList.Builder<PedPerson>(); individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); Assert.assertEquals(pedFileContents.getIndividuals(), individuals.build()); }
@Test public void testParseWithoutHeader() throws PedParseException, IOException { PedFileReader reader = new PedFileReader(this.tmpFileWithoutHeader); PedFileContents pedFileContents = reader.read(); Assert.assertEquals(pedFileContents.getExtraColumnHeaders().size(), 0); ImmutableList.Builder<PedPerson> individuals = new ImmutableList.Builder<PedPerson>(); individuals.add(new PedPerson("fam", "father", "0", "0", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "mother", "0", "0", Sex.FEMALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "son", "father", "mother", Sex.MALE, Disease.UNKNOWN)); individuals.add(new PedPerson("fam", "daughter", "father", "mother", Sex.FEMALE, Disease.UNKNOWN)); Assert.assertEquals(pedFileContents.getIndividuals(), individuals.build()); } |
### Question:
Genotype { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((alleleNumbers == null) ? 0 : alleleNumbers.hashCode()); return result; } Genotype(Collection<Integer> alleleNumbers); ImmutableList<Integer> getAlleleNumbers(); int getPloidy(); boolean isDiploid(); boolean isMonoploid(); boolean isHet(); boolean isHomRef(); boolean isHomAlt(); boolean isNotObserved(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final int NO_CALL; static final int REF_CALL; }### Answer:
@Test public void testHashCode() { Map<Genotype, String> map = new HashMap<>(); map.put(new Genotype(Arrays.asList(1, 2)), "ONE"); map.put(new Genotype(Arrays.asList(1, 2)), "TWO"); map.put(new Genotype(Arrays.asList(1, 1)), "THREE"); Map<Genotype, String> expected = new HashMap<>(); expected.put(new Genotype(Arrays.asList(1, 2)), "TWO"); expected.put(new Genotype(Arrays.asList(1, 1)), "THREE"); assertEquals(expected, map); } |
### Question:
Genotype { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Genotype other = (Genotype) obj; if (alleleNumbers == null) { if (other.alleleNumbers != null) return false; } else if (!alleleNumbers.equals(other.alleleNumbers)) return false; return true; } Genotype(Collection<Integer> alleleNumbers); ImmutableList<Integer> getAlleleNumbers(); int getPloidy(); boolean isDiploid(); boolean isMonoploid(); boolean isHet(); boolean isHomRef(); boolean isHomAlt(); boolean isNotObserved(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final int NO_CALL; static final int REF_CALL; }### Answer:
@Test public void testEquals() { Genotype one = new Genotype(Arrays.asList(1, 2)); Genotype two = new Genotype(Arrays.asList(1, 2)); Genotype three = new Genotype(Arrays.asList(1, 1)); Genotype four = new Genotype(Collections.singletonList(1)); assertTrue(one.equals(two)); assertFalse(one.equals(three)); assertFalse(one.equals(four)); } |
### Question:
ProteinPointLocation implements ConvertibleToHGVSString { @Override public String toHGVSString() { return toHGVSString(AminoAcidCode.THREE_LETTER); } ProteinPointLocation(String aa, int pos, int offset, boolean downstreamOfTerminal); static ProteinPointLocation build(String aa, int pos); static ProteinPointLocation buildWithOffset(String aa, int pos, int offset); static ProteinPointLocation buildDownstreamOfTerminal(String aa, int pos); int getPos(); String getAA(); int getOffset(); boolean isDownstreamOfTerminal(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToHGVSString() { Assert.assertEquals("Ala124", location1.toHGVSString()); Assert.assertEquals("A124", location1.toHGVSString(AminoAcidCode.ONE_LETTER)); Assert.assertEquals("Ala124", location1.toHGVSString(AminoAcidCode.THREE_LETTER)); Assert.assertEquals("Ala124", location1.toHGVSString()); Assert.assertEquals("Cys124", location3.toHGVSString()); Assert.assertEquals("Cys124+1", location4.toHGVSString()); Assert.assertEquals("Cys124-1", location5.toHGVSString()); Assert.assertEquals("Cys*124", location6.toHGVSString()); } |
### Question:
TranscriptSequenceDecorator { public String getCodonAt(TranscriptPosition txPos, CDSPosition cdsPos) throws InvalidCodonException { int frameShift = cdsPos.getPos() % 3; int codonStart = txPos.getPos() - frameShift; int endPos = codonStart + 3; if (transcript.getTrimmedSequence().length() < endPos) throw new InvalidCodonException("Could not access codon " + codonStart + " - " + endPos + ", transcript sequence length is " + transcript.getTrimmedSequence().length()); return transcript.getTrimmedSequence().substring(codonStart, endPos); } TranscriptSequenceDecorator(TranscriptModel transcript); TranscriptModel getTranscript(); static String codonWithUpdatedBase(String transcriptCodon, int frameShift, char targetNC); static String nucleotidesWithInsertion(String transcriptNTs, int frameShift, String insertion); String getCodonAt(TranscriptPosition txPos, CDSPosition cdsPos); String getCodonsStartingFrom(TranscriptPosition txPos, CDSPosition cdsPos, int count); String getCodonsStartingFrom(TranscriptPosition txPos, CDSPosition cdsPos); }### Answer:
@Test public void testGetCodonAt() throws Exception { TranscriptSequenceDecorator decorator = new TranscriptSequenceDecorator(MODEL); Assert.assertEquals(CODONS[CODONS.length - 1], decorator.getCodonAt(tx(START_LAST_CODON), cds(START_LAST_CODON))); Assert.assertEquals(CODONS[0], decorator.getCodonAt(tx(0), cds(0))); } |
### Question:
TranscriptSequenceDecorator { public String getCodonsStartingFrom(TranscriptPosition txPos, CDSPosition cdsPos, int count) { int frameShift = cdsPos.getPos() % 3; int codonStart = txPos.getPos() - frameShift; int endPos = codonStart + 3 * count; if (endPos > transcript.getTrimmedSequence().length()) endPos = transcript.getTrimmedSequence().length(); return transcript.getTrimmedSequence().substring(codonStart, endPos); } TranscriptSequenceDecorator(TranscriptModel transcript); TranscriptModel getTranscript(); static String codonWithUpdatedBase(String transcriptCodon, int frameShift, char targetNC); static String nucleotidesWithInsertion(String transcriptNTs, int frameShift, String insertion); String getCodonAt(TranscriptPosition txPos, CDSPosition cdsPos); String getCodonsStartingFrom(TranscriptPosition txPos, CDSPosition cdsPos, int count); String getCodonsStartingFrom(TranscriptPosition txPos, CDSPosition cdsPos); }### Answer:
@Test public void testGetCodonsStartingFrom() throws Exception { TranscriptSequenceDecorator decorator = new TranscriptSequenceDecorator(MODEL); Assert.assertEquals(CODONS[0] + CODONS[1], decorator.getCodonsStartingFrom(tx(0), cds(0), 2)); Assert.assertEquals(CODONS[CODONS.length - 2] + CODONS[CODONS.length - 1], decorator.getCodonsStartingFrom(tx(9), cds(9), 2)); } |
### Question:
ProteinSubstitution extends ProteinChange { @Override public String toHGVSString(AminoAcidCode code) { if (code == AminoAcidCode.THREE_LETTER) return wrapIfOnlyPredicted(location.toHGVSString(code) + Translator.getTranslator().toLong(targetAA)); else return wrapIfOnlyPredicted(location.toHGVSString(code) + targetAA); } ProteinSubstitution(boolean onlyPredicted, ProteinPointLocation location, String targetAA); static ProteinSubstitution build(boolean onlyPredicted, String sourceAA, int pos, String targetAA); static ProteinSubstitution buildWithOffset(boolean onlyPredicted, String sourceAA, int pos, int offset,
String targetAA); static ProteinSubstitution buildDownstreamOfTerminal(boolean onlyPredicted, String sourceAA, int pos,
String targetAA); ProteinPointLocation getLocation(); String getTargetAA(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); }### Answer:
@Test public void testToHGVSString() { Assert.assertEquals("(A124G)", sub1.toHGVSString(AminoAcidCode.ONE_LETTER)); Assert.assertEquals("(Ala124Gly)", sub1.toHGVSString(AminoAcidCode.THREE_LETTER)); Assert.assertEquals("(A124G)", sub1.toHGVSString()); } |
### Question:
TranscriptProjectionDecorator { public int exonIDInReferenceOrder(int exonID) { if (transcript.getStrand().isForward()) return exonID; else return transcript.getExonRegions().size() - exonID - 1; } TranscriptProjectionDecorator(TranscriptModel transcript); TranscriptModel getTranscript(); String getCDSTranscript(); String getTranscriptStartingAtCDS(); TranscriptPosition genomeToTranscriptPos(GenomePosition pos); CDSPosition genomeToCDSPos(GenomePosition pos); TranscriptPosition cdsToTranscriptPos(CDSPosition pos); GenomePosition cdsToGenomePos(CDSPosition pos); GenomePosition transcriptToGenomePos(TranscriptPosition pos); int exonIDInReferenceOrder(int exonID); int locateIntron(GenomePosition pos); int locateExon(GenomePosition pos); int locateExon(TranscriptPosition pos); CDSPosition projectGenomeToCDSPosition(GenomePosition pos); CDSInterval projectGenomeToCDSInterval(GenomeInterval interval); TranscriptPosition projectGenomeToTXPosition(GenomePosition pos); TranscriptInterval projectGenomeToTXInterval(GenomeInterval interval); static final int INVALID_EXON_ID; static final int INVALID_INTRON_ID; }### Answer:
@Test public void testExonIDInReferenceOrderForward() { TranscriptProjectionDecorator projector = new TranscriptProjectionDecorator(infoForward); for (int i = 0; i < 11; ++i) Assert.assertEquals(i, projector.exonIDInReferenceOrder(i)); }
@Test public void testExonIDInReferenceOrderReverse() { TranscriptProjectionDecorator projector = new TranscriptProjectionDecorator(infoReverse); for (int i = 0; i < 4; ++i) Assert.assertEquals(3 - i, projector.exonIDInReferenceOrder(i)); } |
### Question:
Anchors { public static int gapLength(List<Anchor> anchors) { if (anchors.size() < 2) { throw new RuntimeException("Must have at least two anchors!"); } return anchors.get(anchors.size() - 1).getGapPos(); } static int gapLength(List<Anchor> anchors); static int seqLength(List<Anchor> anchors); static int projectGapToSeqPos(final List<Anchor> anchors, final int gapPos); static int projectSeqToGapPos(final List<Anchor> anchors, final int seqPos); static int countLeadingGaps(List<Anchor> anchors); static int countTrailingGaps(List<Anchor> anchors); }### Answer:
@Test public void testGapLength() { assertEquals(10, Anchors.gapLength(ungapped)); assertEquals(10, Anchors.gapLength(leadingGap)); assertEquals(10, Anchors.gapLength(oneGap)); assertEquals(10, Anchors.gapLength(twoGaps)); assertEquals(10, Anchors.gapLength(trailingGap)); } |
### Question:
Anchors { public static int seqLength(List<Anchor> anchors) { if (anchors.size() < 2) { throw new RuntimeException("Must have at least two anchors!"); } return anchors.get(anchors.size() - 1).getSeqPos(); } static int gapLength(List<Anchor> anchors); static int seqLength(List<Anchor> anchors); static int projectGapToSeqPos(final List<Anchor> anchors, final int gapPos); static int projectSeqToGapPos(final List<Anchor> anchors, final int seqPos); static int countLeadingGaps(List<Anchor> anchors); static int countTrailingGaps(List<Anchor> anchors); }### Answer:
@Test public void testSeqLength() { assertEquals(10, Anchors.seqLength(ungapped)); assertEquals(8, Anchors.seqLength(leadingGap)); assertEquals(8, Anchors.seqLength(oneGap)); assertEquals(8, Anchors.seqLength(twoGaps)); assertEquals(8, Anchors.seqLength(trailingGap)); } |
### Question:
Anchors { public static int countLeadingGaps(List<Anchor> anchors) { if (anchors.size() < 2) { throw new RuntimeException("Must have at least two anchors!"); } else if (anchors.size() < 2 || (anchors.get(0).getSeqPos() != anchors.get(1) .getSeqPos())) { return 0; } else { assert anchors.get(0).getSeqPos() == 0; return anchors.get(1).getGapPos(); } } static int gapLength(List<Anchor> anchors); static int seqLength(List<Anchor> anchors); static int projectGapToSeqPos(final List<Anchor> anchors, final int gapPos); static int projectSeqToGapPos(final List<Anchor> anchors, final int seqPos); static int countLeadingGaps(List<Anchor> anchors); static int countTrailingGaps(List<Anchor> anchors); }### Answer:
@Test public void testCountLeadingGaps() { assertEquals(0, Anchors.countLeadingGaps(ungapped)); assertEquals(2, Anchors.countLeadingGaps(leadingGap)); assertEquals(0, Anchors.countLeadingGaps(oneGap)); assertEquals(0, Anchors.countLeadingGaps(twoGaps)); assertEquals(0, Anchors.countLeadingGaps(trailingGap)); } |
### Question:
Anchors { public static int countTrailingGaps(List<Anchor> anchors) { final int len = anchors.size(); if (len < 2) { throw new RuntimeException("Must have at least two anchors!"); } else if ((anchors.get(len - 1).getSeqPos() != anchors.get(len - 2).getSeqPos())) { return 0; } else { return anchors.get(len - 1).getGapPos() - anchors.get(len - 2).getGapPos(); } } static int gapLength(List<Anchor> anchors); static int seqLength(List<Anchor> anchors); static int projectGapToSeqPos(final List<Anchor> anchors, final int gapPos); static int projectSeqToGapPos(final List<Anchor> anchors, final int seqPos); static int countLeadingGaps(List<Anchor> anchors); static int countTrailingGaps(List<Anchor> anchors); }### Answer:
@Test public void testCountTrailingGaps() { assertEquals(0, Anchors.countTrailingGaps(ungapped)); assertEquals(0, Anchors.countTrailingGaps(leadingGap)); assertEquals(0, Anchors.countTrailingGaps(oneGap)); assertEquals(0, Anchors.countTrailingGaps(twoGaps)); assertEquals(2, Anchors.countTrailingGaps(trailingGap)); } |
### Question:
Alignment implements Serializable { public int refLeadingGapLength() { return Anchors.countLeadingGaps(refAnchors); } Alignment(List<Anchor> refAnchors, List<Anchor> qryAnchors); static Alignment createUngappedAlignment(int length); ImmutableList<Anchor> getRefAnchors(); ImmutableList<Anchor> getQryAnchors(); int refLeadingGapLength(); int refTrailingGapLength(); int qryLeadingGapLength(); int qryTrailingGapLength(); int projectRefToQry(int refPos); int projectQryToRef(int qryPos); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }### Answer:
@Test public void refLeadingGapLength() { assertEquals(0, ungapped.refLeadingGapLength()); assertEquals(0, overlap.refLeadingGapLength()); assertEquals(0, refIsLonger.refLeadingGapLength()); assertEquals(2, qryIsLonger.refLeadingGapLength()); } |
### Question:
Alignment implements Serializable { public int refTrailingGapLength() { return Anchors.countTrailingGaps(refAnchors); } Alignment(List<Anchor> refAnchors, List<Anchor> qryAnchors); static Alignment createUngappedAlignment(int length); ImmutableList<Anchor> getRefAnchors(); ImmutableList<Anchor> getQryAnchors(); int refLeadingGapLength(); int refTrailingGapLength(); int qryLeadingGapLength(); int qryTrailingGapLength(); int projectRefToQry(int refPos); int projectQryToRef(int qryPos); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }### Answer:
@Test public void refTrailingGapLength() { assertEquals(0, ungapped.refTrailingGapLength()); assertEquals(2, overlap.refTrailingGapLength()); assertEquals(0, refIsLonger.refTrailingGapLength()); assertEquals(2, qryIsLonger.refTrailingGapLength()); } |
### Question:
Alignment implements Serializable { public int qryLeadingGapLength() { return Anchors.countLeadingGaps(qryAnchors); } Alignment(List<Anchor> refAnchors, List<Anchor> qryAnchors); static Alignment createUngappedAlignment(int length); ImmutableList<Anchor> getRefAnchors(); ImmutableList<Anchor> getQryAnchors(); int refLeadingGapLength(); int refTrailingGapLength(); int qryLeadingGapLength(); int qryTrailingGapLength(); int projectRefToQry(int refPos); int projectQryToRef(int qryPos); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }### Answer:
@Test public void qryLeadingGapLength() { assertEquals(0, ungapped.qryLeadingGapLength()); assertEquals(2, overlap.qryLeadingGapLength()); assertEquals(2, refIsLonger.qryLeadingGapLength()); assertEquals(0, qryIsLonger.qryLeadingGapLength()); } |
### Question:
Alignment implements Serializable { public int qryTrailingGapLength() { return Anchors.countTrailingGaps(qryAnchors); } Alignment(List<Anchor> refAnchors, List<Anchor> qryAnchors); static Alignment createUngappedAlignment(int length); ImmutableList<Anchor> getRefAnchors(); ImmutableList<Anchor> getQryAnchors(); int refLeadingGapLength(); int refTrailingGapLength(); int qryLeadingGapLength(); int qryTrailingGapLength(); int projectRefToQry(int refPos); int projectQryToRef(int qryPos); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }### Answer:
@Test public void qryTrailingGapLength() { assertEquals(0, ungapped.qryTrailingGapLength()); assertEquals(0, overlap.qryTrailingGapLength()); assertEquals(2, refIsLonger.qryTrailingGapLength()); assertEquals(0, qryIsLonger.qryTrailingGapLength()); } |
### Question:
GenomeInterval implements Serializable, Comparable<GenomeInterval> { public boolean isLeftOf(GenomePosition pos) { if (chr != pos.getChr()) return false; pos = ensureSameStrand(pos); return (pos.getPos() >= endPos); } GenomeInterval(ReferenceDictionary refDict, Strand strand, int chr, int beginPos, int endPos); GenomeInterval(ReferenceDictionary refDict, Strand strand, int chr, int beginPos, int endPos,
PositionType positionType); GenomeInterval(GenomePosition pos, int length); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getBeginPos(); int getEndPos(); GenomeInterval withStrand(Strand strand); GenomePosition getGenomeBeginPos(); GenomePosition getGenomeEndPos(); int length(); GenomeInterval intersection(GenomeInterval other); GenomeInterval union(GenomeInterval other); boolean isLeftOf(GenomePosition pos); boolean isRightOf(GenomePosition pos); boolean isLeftOfGap(GenomePosition pos); boolean isRightOfGap(GenomePosition pos); boolean contains(GenomePosition pos); boolean contains(GenomeInterval other); GenomeInterval withMorePadding(int padding); GenomeInterval withMorePadding(int paddingUpstream, int paddingDownstream); boolean overlapsWith(GenomeInterval other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(GenomeInterval other); }### Answer:
@Test public void testIsLeftOf() { GenomeInterval interval = new GenomeInterval(refDict, Strand.FWD, 1, 1000, 1200, PositionType.ONE_BASED); Assert.assertTrue(interval.isRightOf(new GenomePosition(refDict, Strand.FWD, 1, 999, PositionType.ONE_BASED))); Assert.assertFalse(interval .isRightOf(new GenomePosition(refDict, Strand.FWD, 1, 1000, PositionType.ONE_BASED))); } |
### Question:
GenomeInterval implements Serializable, Comparable<GenomeInterval> { public boolean isRightOf(GenomePosition pos) { if (chr != pos.getChr()) return false; pos = ensureSameStrand(pos); return (pos.getPos() < beginPos); } GenomeInterval(ReferenceDictionary refDict, Strand strand, int chr, int beginPos, int endPos); GenomeInterval(ReferenceDictionary refDict, Strand strand, int chr, int beginPos, int endPos,
PositionType positionType); GenomeInterval(GenomePosition pos, int length); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getBeginPos(); int getEndPos(); GenomeInterval withStrand(Strand strand); GenomePosition getGenomeBeginPos(); GenomePosition getGenomeEndPos(); int length(); GenomeInterval intersection(GenomeInterval other); GenomeInterval union(GenomeInterval other); boolean isLeftOf(GenomePosition pos); boolean isRightOf(GenomePosition pos); boolean isLeftOfGap(GenomePosition pos); boolean isRightOfGap(GenomePosition pos); boolean contains(GenomePosition pos); boolean contains(GenomeInterval other); GenomeInterval withMorePadding(int padding); GenomeInterval withMorePadding(int paddingUpstream, int paddingDownstream); boolean overlapsWith(GenomeInterval other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(GenomeInterval other); }### Answer:
@Test public void testIsRightOf() { GenomeInterval interval = new GenomeInterval(refDict, Strand.FWD, 1, 1000, 1200, PositionType.ONE_BASED); Assert.assertFalse(interval.isLeftOf(new GenomePosition(refDict, Strand.FWD, 1, 1200, PositionType.ONE_BASED))); Assert.assertTrue(interval.isLeftOf(new GenomePosition(refDict, Strand.FWD, 1, 1201, PositionType.ONE_BASED))); } |
### Question:
GenomePosition implements Serializable, Comparable<GenomePosition> { public boolean isLt(GenomePosition other) { if (other.strand != strand) other = other.withStrand(strand); return (pos < other.pos); } GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos); GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos, PositionType positionType); GenomePosition(GenomePosition other); GenomePosition(GenomePosition other, Strand strand); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getPos(); GenomePosition withStrand(Strand strand); boolean isLt(GenomePosition other); boolean isLeq(GenomePosition other); boolean isGt(GenomePosition other); boolean isGeq(GenomePosition other); boolean isEq(GenomePosition other); int differenceTo(GenomePosition pos); int differenceTo(GenomeInterval itv); GenomePosition shifted(int delta); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(GenomePosition other); }### Answer:
@Test public void testLt() { GenomePosition posL = new GenomePosition(refDict, Strand.FWD, 1, 100, PositionType.ONE_BASED); GenomePosition posR = new GenomePosition(refDict, Strand.FWD, 1, 101, PositionType.ONE_BASED); Assert.assertTrue(posL.isLt(posR)); Assert.assertFalse(posL.isLt(posL)); Assert.assertFalse(posR.isLt(posL)); } |
### Question:
GenomePosition implements Serializable, Comparable<GenomePosition> { public boolean isLeq(GenomePosition other) { if (other.chr != chr) return false; if (other.strand != strand) other = other.withStrand(strand); return (pos <= other.pos); } GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos); GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos, PositionType positionType); GenomePosition(GenomePosition other); GenomePosition(GenomePosition other, Strand strand); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getPos(); GenomePosition withStrand(Strand strand); boolean isLt(GenomePosition other); boolean isLeq(GenomePosition other); boolean isGt(GenomePosition other); boolean isGeq(GenomePosition other); boolean isEq(GenomePosition other); int differenceTo(GenomePosition pos); int differenceTo(GenomeInterval itv); GenomePosition shifted(int delta); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(GenomePosition other); }### Answer:
@Test public void testLeq() { GenomePosition posL = new GenomePosition(refDict, Strand.FWD, 1, 100, PositionType.ONE_BASED); GenomePosition posR = new GenomePosition(refDict, Strand.FWD, 1, 101, PositionType.ONE_BASED); Assert.assertTrue(posL.isLeq(posR)); Assert.assertTrue(posL.isLeq(posL)); Assert.assertFalse(posR.isLeq(posL)); } |
### Question:
GenomePosition implements Serializable, Comparable<GenomePosition> { public boolean isGt(GenomePosition other) { if (other.chr != chr) return false; if (other.strand != strand) other = other.withStrand(strand); return (pos > other.pos); } GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos); GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos, PositionType positionType); GenomePosition(GenomePosition other); GenomePosition(GenomePosition other, Strand strand); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getPos(); GenomePosition withStrand(Strand strand); boolean isLt(GenomePosition other); boolean isLeq(GenomePosition other); boolean isGt(GenomePosition other); boolean isGeq(GenomePosition other); boolean isEq(GenomePosition other); int differenceTo(GenomePosition pos); int differenceTo(GenomeInterval itv); GenomePosition shifted(int delta); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(GenomePosition other); }### Answer:
@Test public void testGt() { GenomePosition posL = new GenomePosition(refDict, Strand.FWD, 1, 100, PositionType.ONE_BASED); GenomePosition posR = new GenomePosition(refDict, Strand.FWD, 1, 101, PositionType.ONE_BASED); Assert.assertFalse(posL.isGt(posR)); Assert.assertFalse(posL.isGt(posL)); Assert.assertTrue(posR.isGt(posL)); } |
### Question:
GenomePosition implements Serializable, Comparable<GenomePosition> { public boolean isGeq(GenomePosition other) { if (other.chr != chr) return false; if (other.strand != strand) other = other.withStrand(strand); return (pos >= other.pos); } GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos); GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos, PositionType positionType); GenomePosition(GenomePosition other); GenomePosition(GenomePosition other, Strand strand); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getPos(); GenomePosition withStrand(Strand strand); boolean isLt(GenomePosition other); boolean isLeq(GenomePosition other); boolean isGt(GenomePosition other); boolean isGeq(GenomePosition other); boolean isEq(GenomePosition other); int differenceTo(GenomePosition pos); int differenceTo(GenomeInterval itv); GenomePosition shifted(int delta); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(GenomePosition other); }### Answer:
@Test public void testGeq() { GenomePosition posL = new GenomePosition(refDict, Strand.FWD, 1, 100, PositionType.ONE_BASED); GenomePosition posR = new GenomePosition(refDict, Strand.FWD, 1, 101, PositionType.ONE_BASED); Assert.assertFalse(posL.isGeq(posR)); Assert.assertTrue(posL.isGeq(posL)); Assert.assertTrue(posR.isGeq(posL)); } |
### Question:
GenomePosition implements Serializable, Comparable<GenomePosition> { public boolean isEq(GenomePosition other) { if (other.chr != chr) return false; if (other.strand != strand) other = other.withStrand(strand); return (pos == other.pos); } GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos); GenomePosition(ReferenceDictionary refDict, Strand strand, int chr, int pos, PositionType positionType); GenomePosition(GenomePosition other); GenomePosition(GenomePosition other, Strand strand); ReferenceDictionary getRefDict(); Strand getStrand(); int getChr(); int getPos(); GenomePosition withStrand(Strand strand); boolean isLt(GenomePosition other); boolean isLeq(GenomePosition other); boolean isGt(GenomePosition other); boolean isGeq(GenomePosition other); boolean isEq(GenomePosition other); int differenceTo(GenomePosition pos); int differenceTo(GenomeInterval itv); GenomePosition shifted(int delta); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(GenomePosition other); }### Answer:
@Test public void testEq() { GenomePosition posL = new GenomePosition(refDict, Strand.FWD, 1, 100, PositionType.ONE_BASED); GenomePosition posR = new GenomePosition(refDict, Strand.FWD, 1, 101, PositionType.ONE_BASED); Assert.assertFalse(posL.isEq(posR)); Assert.assertTrue(posL.isEq(posL)); Assert.assertFalse(posR.isEq(posL)); } |
### Question:
NucleotideRange implements ConvertibleToHGVSString { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; NucleotideRange other = (NucleotideRange) obj; if (firstPos == null) { if (other.firstPos != null) return false; } else if (!firstPos.equals(other.firstPos)) return false; if (lastPos == null) { if (other.lastPos != null) return false; } else if (!lastPos.equals(other.lastPos)) return false; return true; } NucleotideRange(NucleotidePointLocation firstPos, NucleotidePointLocation lastPost); static NucleotideRange build(int firstPos, int firstPosOffset, int lastPos, int lastPosOffset); static NucleotideRange buildWithoutOffset(int firstPos, int lastPos); NucleotidePointLocation getFirstPos(); NucleotidePointLocation getLastPos(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testEquals() { Assert.assertEquals(firstLoc, firstLoc2); Assert.assertNotEquals(lastLoc, firstLoc); } |
### Question:
NucleotideRange implements ConvertibleToHGVSString { @Override public String toHGVSString() { if (firstPos.equals(lastPos)) return firstPos.toHGVSString(); else return Joiner.on("").join(firstPos.toHGVSString(), "_", lastPos.toHGVSString()); } NucleotideRange(NucleotidePointLocation firstPos, NucleotidePointLocation lastPost); static NucleotideRange build(int firstPos, int firstPosOffset, int lastPos, int lastPosOffset); static NucleotideRange buildWithoutOffset(int firstPos, int lastPos); NucleotidePointLocation getFirstPos(); NucleotidePointLocation getLastPos(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToHGVSStringRange() { NucleotideRange range = new NucleotideRange(firstLoc, lastLoc); Assert.assertEquals("124_235-1", range.toHGVSString(AminoAcidCode.ONE_LETTER)); Assert.assertEquals("124_235-1", range.toHGVSString(AminoAcidCode.THREE_LETTER)); }
@Test public void testToHGVSStringSinglePos() { NucleotideRange range = new NucleotideRange(firstLoc, firstLoc2); Assert.assertEquals("124", range.toHGVSString(AminoAcidCode.ONE_LETTER)); Assert.assertEquals("124", range.toHGVSString(AminoAcidCode.THREE_LETTER)); } |
### Question:
GenomeVariant implements VariantDescription { public GenomeInterval getGenomeInterval() { return new GenomeInterval(pos, ref.length()); } GenomeVariant(GenomePosition pos, String ref, String alt); GenomeVariant(GenomePosition pos, String ref, String alt, Strand strand); static boolean wouldBeSymbolicAllele(String allele); @Override String getChrName(); GenomePosition getGenomePos(); @Override int getPos(); @Override String getRef(); @Override String getAlt(); @Override int getChr(); GenomeInterval getGenomeInterval(); GenomeVariant withStrand(Strand strand); @Override String toString(); GenomeVariantType getType(); boolean isTransition(); boolean isTransversion(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(Annotation other); }### Answer:
@Test public void testGetGenomeIntervalForward() { GenomeVariant change = new GenomeVariant(this.genomePosOneBasedForward, "A", "C"); GenomeInterval genomeInterval = change.getGenomeInterval(); GenomeInterval expectedInterval = new GenomeInterval(refDict, Strand.FWD, 1, 123, 123, PositionType.ONE_BASED); Assert.assertEquals(expectedInterval, genomeInterval); Assert.assertEquals(expectedInterval, genomeInterval); } |
### Question:
Translator { public String translateDNA(String dnaseq) { return translateDNA(dnaseq, this.codon1); } private Translator(); static Translator getTranslator(); String translateDNA(String dnaseq); String translateDNA3(String dnaseq); String toLong(String shortAASeq); String toLong(char c); }### Answer:
@Test public void testTranslateDna_tooShort() throws AnnotationException { Assert.assertEquals("", translator.translateDNA("A")); Assert.assertEquals("", translator.translateDNA("AC")); }
@Test public void testTranslateDna_short() throws AnnotationException { Assert.assertEquals("T", translator.translateDNA("ACT")); }
@Test public void testTranslateDna_longer() throws AnnotationException { Assert.assertEquals("M*S", translator.translateDNA("ATGTAGAGT")); }
@Test public void testTranslateDna_tooLonger() throws AnnotationException { Assert.assertEquals("T", translator.translateDNA("ACTG")); } |
### Question:
NucleotidePointLocation implements ConvertibleToHGVSString { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; NucleotidePointLocation other = (NucleotidePointLocation) obj; if (basePos != other.basePos) return false; if (downstreamOfCDS != other.downstreamOfCDS) return false; if (offset != other.offset) return false; return true; } @Deprecated // in favour of full constructor NucleotidePointLocation(int basePos); NucleotidePointLocation(int basePos, int offset, boolean downstreamOfCDS); static NucleotidePointLocation build(int basePos); static NucleotidePointLocation buildWithOffset(int basePos, int offset); static NucleotidePointLocation buildDownstreamOfCDS(int basePos); int getBasePos(); int getOffset(); boolean isDownstreamOfCDS(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testEquals() { NucleotidePointLocation location1 = new NucleotidePointLocation(123, -3, false); NucleotidePointLocation location2 = new NucleotidePointLocation(123, -3, false); NucleotidePointLocation location3 = new NucleotidePointLocation(123, 3, false); Assert.assertTrue(location1.equals(location2)); Assert.assertTrue(location2.equals(location1)); Assert.assertFalse(location1.equals(location3)); Assert.assertFalse(location3.equals(location1)); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public boolean allLeftOf(int point) { return (maxEnd <= point); } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void testAllLeftOf() { Assert.assertFalse(interval.allLeftOf(10)); Assert.assertFalse(interval.allLeftOf(12)); Assert.assertTrue(interval.allLeftOf(13)); Assert.assertTrue(interval.allLeftOf(14)); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public int compareTo(Interval<T> o) { final int result = (begin - o.begin); if (result == 0) return (end - o.end); return result; } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void testCompareTo() { Assert.assertTrue(interval.compareTo(new Interval<String>(0, 10, "y", 10)) > 0); Assert.assertTrue(interval.compareTo(new Interval<String>(1, 9, "y", 10)) > 0); Assert.assertTrue(interval.compareTo(new Interval<String>(1, 10, "y", 10)) == 0); Assert.assertTrue(interval.compareTo(new Interval<String>(1, 11, "y", 10)) < 0); Assert.assertTrue(interval.compareTo(new Interval<String>(2, 10, "y", 10)) < 0); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public boolean contains(int point) { return ((begin <= point) && (point < end)); } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void testContains() { Assert.assertFalse(interval.contains(0)); Assert.assertTrue(interval.contains(1)); Assert.assertTrue(interval.contains(2)); Assert.assertTrue(interval.contains(9)); Assert.assertFalse(interval.contains(10)); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public boolean isLeftOf(int point) { return (end <= point); } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void testIsLeftOf() { Assert.assertFalse(interval.isLeftOf(8)); Assert.assertFalse(interval.isLeftOf(9)); Assert.assertTrue(interval.isLeftOf(10)); Assert.assertTrue(interval.isLeftOf(11)); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public boolean isRightOf(int point) { return (point < begin); } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void testIsRightOf() { Assert.assertTrue(interval.isRightOf(-1)); Assert.assertTrue(interval.isRightOf(0)); Assert.assertFalse(interval.isRightOf(1)); Assert.assertFalse(interval.isRightOf(2)); } |
### Question:
Interval implements java.io.Serializable, Comparable<Interval<T>> { public boolean overlapsWith(int begin, int end) { return ((begin < this.end) && (this.begin < end)); } Interval(MutableInterval<T> other); Interval(int begin, int end, T value, int maxEnd); int getBegin(); int getEnd(); T getValue(); int getMaxEnd(); boolean allLeftOf(int point); boolean isLeftOf(int point); boolean isRightOf(int point); boolean contains(int point); boolean overlapsWith(int begin, int end); @Override int hashCode(); @Override boolean equals(Object obj); int compareTo(Interval<T> o); @Override String toString(); }### Answer:
@Test public void overlapsWith() { Assert.assertTrue(interval.overlapsWith(0, 2)); Assert.assertTrue(interval.overlapsWith(0, 3)); Assert.assertTrue(interval.overlapsWith(0, 20)); Assert.assertTrue(interval.overlapsWith(9, 10)); Assert.assertFalse(interval.overlapsWith(0, 1)); Assert.assertFalse(interval.overlapsWith(10, 11)); } |
### Question:
FASTAParser { public FASTARecord next() throws IOException { if (lastLine == null) return null; assert lastLine.startsWith(">"); while (true) { if (lastLine != null && !lastLine.isEmpty()) recordBuffer.add(lastLine); lastLine = reader.readLine(); if (lastLine == null || lastLine.startsWith(">")) break; } return buildRecord(); } FASTAParser(File file); FASTAParser(InputStream stream); FASTARecord next(); }### Answer:
@Test public void test() throws IOException { FASTAParser parser = new FASTAParser(stream); FASTARecord first = parser.next(); Assert.assertEquals("1", first.getID()); Assert.assertEquals("comment 1", first.getComment()); Assert.assertEquals("ACGTAACTACGT", first.getSequence()); FASTARecord second = parser.next(); Assert.assertEquals("2", second.getID()); Assert.assertEquals("comment 2", second.getComment()); Assert.assertEquals("AAAA", second.getSequence()); FASTARecord third = parser.next(); Assert.assertNull(third); } |
### Question:
RefSeqParser implements TranscriptParser { private boolean onlyCurated() { return checkFlagInSection(iniSection.fetch("onlyCurated")); } RefSeqParser(ReferenceDictionary refDict, String basePath, List<String> geneIdentifiers,
Section iniSection); @Override ImmutableList<TranscriptModel> run(); }### Answer:
@Test public void testOnlyCurated() throws TranscriptParseException { RefSeqParser parser = new RefSeqParser(refDict, dataDirectory.getAbsolutePath(), new ArrayList<>(), curatedIniSection); ImmutableList<TranscriptModel> result = parser.run(); Assert.assertEquals(6, result.size()); SortedSet<String> values = new TreeSet<String>(); for (TranscriptModel tx : result) { values.add(tx.toString()); } SortedSet<String> expected = new TreeSet<String>(); expected.addAll(Lists.newArrayList("NM_000539.3(3:g.129247482_129254187)", "NM_001025596.2(11:g.47487489_47510576)", "NM_001172639.1(11:g.47487489_47545540)", "NM_001172640.1(11:g.47487489_47510576)", "NM_006560.3(11:g.47487489_47574792)", "NM_198700.2(11:g.47487489_47516073)")); Assert.assertEquals(expected, values); } |
### Question:
NucleotidePointLocation implements ConvertibleToHGVSString { @Override public String toHGVSString() { final int shift = (this.basePos >= 0) ? 1 : 0; final String prefix = downstreamOfCDS ? "*" : ""; if (offset == 0) return prefix + Integer.toString(this.basePos + shift); else if (offset > 0) return prefix + Joiner.on("").join(this.basePos + shift, "+", offset); else return prefix + Joiner.on("").join(this.basePos + shift, "-", -offset); } @Deprecated // in favour of full constructor NucleotidePointLocation(int basePos); NucleotidePointLocation(int basePos, int offset, boolean downstreamOfCDS); static NucleotidePointLocation build(int basePos); static NucleotidePointLocation buildWithOffset(int basePos, int offset); static NucleotidePointLocation buildDownstreamOfCDS(int basePos); int getBasePos(); int getOffset(); boolean isDownstreamOfCDS(); @Override String toHGVSString(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToHGVSString() { NucleotidePointLocation location1 = new NucleotidePointLocation(123, -3, false); NucleotidePointLocation location2 = new NucleotidePointLocation(123, 0, true); Assert.assertEquals("124-3", location1.toHGVSString()); Assert.assertEquals("124-3", location1.toHGVSString(AminoAcidCode.ONE_LETTER)); Assert.assertEquals("124-3", location1.toHGVSString(AminoAcidCode.THREE_LETTER)); Assert.assertEquals("*124", location2.toHGVSString()); } |
### Question:
ProteinSubstitution extends ProteinChange { public static ProteinSubstitution build(boolean onlyPredicted, String sourceAA, int pos, String targetAA) { return new ProteinSubstitution(onlyPredicted, ProteinPointLocation.build(sourceAA, pos), targetAA); } ProteinSubstitution(boolean onlyPredicted, ProteinPointLocation location, String targetAA); static ProteinSubstitution build(boolean onlyPredicted, String sourceAA, int pos, String targetAA); static ProteinSubstitution buildWithOffset(boolean onlyPredicted, String sourceAA, int pos, int offset,
String targetAA); static ProteinSubstitution buildDownstreamOfTerminal(boolean onlyPredicted, String sourceAA, int pos,
String targetAA); ProteinPointLocation getLocation(); String getTargetAA(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); }### Answer:
@Test public void testFactoryMethod() { Assert.assertEquals(sub1, ProteinSubstitution.build(true, "A", 123, "G")); } |
### Question:
NucleotideShortSequenceRepeatVariability extends NucleotideChange { @Override public String toHGVSString() { return wrapIfOnlyPredicted(Joiner.on("").join(range.toHGVSString(), "(", minCount, "_", maxCount, ")")); } NucleotideShortSequenceRepeatVariability(boolean onlyPredicted, NucleotideRange range, int minCount,
int maxCount); static NucleotideShortSequenceRepeatVariability build(boolean onlyPredicted, NucleotideRange range,
int minCount, int maxCount); @Override NucleotideShortSequenceRepeatVariability withOnlyPredicted(boolean flag); NucleotideRange getRange(); int getMinCount(); int getMaxCount(); @Override String toHGVSString(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToHGVSString() { Assert.assertEquals("21_24(1_2)", srr.toHGVSString()); Assert.assertEquals("21_24(3_6)", srr2.toHGVSString()); } |
### Question:
NucleotideSubstitution extends NucleotideChange { public static NucleotideSubstitution buildWithOffset(boolean onlyPredicted, int basePos, int posOffset, String fromNT, String toNT) { return new NucleotideSubstitution(onlyPredicted, NucleotidePointLocation.buildWithOffset(basePos, posOffset), fromNT, toNT); } NucleotideSubstitution(boolean onlyPredicted, NucleotidePointLocation position, String fromNT, String toNT); static NucleotideSubstitution buildWithOffset(boolean onlyPredicted, int basePos, int posOffset,
String fromNT, String toNT); static NucleotideSubstitution build(boolean onlyPredicted, int basePos, String fromNT, String toNT); @Override NucleotideSubstitution withOnlyPredicted(boolean flag); NucleotidePointLocation getPosition(); String getFromNT(); String getToNT(); @Override String toHGVSString(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testBuildWithOffset() { Assert.assertEquals(subWithOffset, NucleotideSubstitution.buildWithOffset(true, 10, 1, "A", "T")); }
@Test public void testBuildWithoutOffset() { Assert.assertEquals(subWithoutOffset, NucleotideSubstitution.buildWithOffset(true, 10, 0, "A", "T")); } |
### Question:
NucleotideSubstitution extends NucleotideChange { @Override public String toHGVSString() { return wrapIfOnlyPredicted(Joiner.on("").join(position.toHGVSString(), fromNT, ">", toNT)); } NucleotideSubstitution(boolean onlyPredicted, NucleotidePointLocation position, String fromNT, String toNT); static NucleotideSubstitution buildWithOffset(boolean onlyPredicted, int basePos, int posOffset,
String fromNT, String toNT); static NucleotideSubstitution build(boolean onlyPredicted, int basePos, String fromNT, String toNT); @Override NucleotideSubstitution withOnlyPredicted(boolean flag); NucleotidePointLocation getPosition(); String getFromNT(); String getToNT(); @Override String toHGVSString(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); }### Answer:
@Test public void testToStringWithOffset() { Assert.assertEquals("(11+1A>T)", subWithOffset.toHGVSString()); }
@Test public void testToStringWithoutOffset() { Assert.assertEquals("(11A>T)", subWithoutOffset.toHGVSString()); } |
### Question:
ProteinFrameshift extends ProteinChange { public static ProteinFrameshift build(boolean onlyPredicted, String wtAA, int position, String targetAA, int shiftLength) { return new ProteinFrameshift(onlyPredicted, ProteinPointLocation.build(wtAA, position), targetAA, shiftLength); } ProteinFrameshift(boolean onlyPredicted, ProteinPointLocation position, String targetAA, int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, String wtAA, int position, String targetAA,
int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, ProteinPointLocation position, String targetAA,
int shiftLength); static ProteinFrameshift buildShort(boolean onlyPredicted, String wtAA, int position); static ProteinFrameshift buildShort(boolean onlyPredicted, ProteinPointLocation position); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, String wtAA, int position,
String targetAA); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, ProteinPointLocation position,
String targetAA); boolean isShort(); boolean isNoTerminalFrameshfit(); ProteinPointLocation getPosition(); String getTargetAA(); int getShiftLength(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); static final int LEN_NO_TER; static final int LEN_SHORT; }### Answer:
@Test public void testConstructFullFrameshift() { Assert.assertEquals(fullFrameshift, ProteinFrameshift.build(false, position, "T", 23)); } |
### Question:
ClinVarVCFHeaderExtender extends VCFHeaderExtender { @Override public void addHeaders(VCFHeader header, String prefix) { addHeaders(header, prefix, "", ""); final String note = " (requiring no genotype match, only position overlap)"; if (options.isReportOverlapping() && !options.isReportOverlappingAsMatching()) addHeaders(header, prefix, "OVL_", note); } ClinVarVCFHeaderExtender(DBAnnotationOptions options); @Override String getDefaultPrefix(); @Override void addHeaders(VCFHeader header, String prefix); }### Answer:
@Test public void test() { VCFHeader header = new VCFHeader(); Assert.assertEquals(0, header.getFilterLines().size()); Assert.assertEquals(0, header.getInfoHeaderLines().size()); Assert.assertEquals(0, header.getFormatHeaderLines().size()); Assert.assertEquals(0, header.getIDHeaderLines().size()); Assert.assertEquals(0, header.getOtherHeaderLines().size()); DBAnnotationOptions options = DBAnnotationOptions.createDefaults(); options.setReportOverlapping(true); options.setReportOverlappingAsMatching(false); options.setIdentifierPrefix("CLINVAR_"); new ClinVarVCFHeaderExtender(options).addHeaders(header); Assert.assertEquals(0, header.getFilterLines().size()); Assert.assertEquals(6, header.getInfoHeaderLines().size()); Assert.assertEquals(0, header.getFormatHeaderLines().size()); Assert.assertEquals(6, header.getIDHeaderLines().size()); Assert.assertEquals(0, header.getOtherHeaderLines().size()); Assert.assertNotNull(header.getInfoHeaderLine("CLINVAR_BASIC_INFO")); Assert.assertNotNull(header.getInfoHeaderLine("CLINVAR_VAR_INFO")); Assert.assertNotNull(header.getInfoHeaderLine("CLINVAR_DISEASE_INFO")); } |
### Question:
CosmicVariantContextToRecordConverter implements VariantContextToRecordConverter<CosmicRecord> { @Override public CosmicRecord convert(VariantContext vc) { CosmicRecordBuilder builder = new CosmicRecordBuilder(); builder.setContig(vc.getContig()); builder.setPos(vc.getStart() - 1); builder.setID(vc.getID()); builder.setRef(vc.getReference().getBaseString()); for (Allele all : vc.getAlternateAlleles()) builder.getAlt().add(all.getBaseString()); builder.setSnp(vc.getAttributeAsBoolean("SNP", false)); builder.setCnt(vc.getAttributeAsInt("CNT", 0)); return builder.build(); } @Override CosmicRecord convert(VariantContext vc); }### Answer:
@Test public void test() { CosmicVariantContextToRecordConverter converter = new CosmicVariantContextToRecordConverter(); VariantContext vc = vcfReader.iterator().next(); CosmicRecord record = converter.convert(vc); Assert.assertEquals("CosmicRecord [chrom=1, pos=1230, id=COSM1231, ref=A, alt=[C], cnt=1, snp=false]", record.toString()); } |
### Question:
ProteinFrameshift extends ProteinChange { public static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, String wtAA, int position, String targetAA) { return new ProteinFrameshift(onlyPredicted, ProteinPointLocation.build(wtAA, position), targetAA, LEN_NO_TER); } ProteinFrameshift(boolean onlyPredicted, ProteinPointLocation position, String targetAA, int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, String wtAA, int position, String targetAA,
int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, ProteinPointLocation position, String targetAA,
int shiftLength); static ProteinFrameshift buildShort(boolean onlyPredicted, String wtAA, int position); static ProteinFrameshift buildShort(boolean onlyPredicted, ProteinPointLocation position); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, String wtAA, int position,
String targetAA); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, ProteinPointLocation position,
String targetAA); boolean isShort(); boolean isNoTerminalFrameshfit(); ProteinPointLocation getPosition(); String getTargetAA(); int getShiftLength(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); static final int LEN_NO_TER; static final int LEN_SHORT; }### Answer:
@Test public void testConstructNoTerFrameshift() { Assert.assertEquals(noTerFrameshift, ProteinFrameshift.buildWithoutTerminal(false, position, "T")); } |
### Question:
UK10KVariantContextToRecordConverter implements VariantContextToRecordConverter<UK10KRecord> { @Override public UK10KRecord convert(VariantContext vc) { UK10KRecordBuilder builder = new UK10KRecordBuilder(); builder.setContig(vc.getContig()); builder.setPos(vc.getStart() - 1); builder.setID(vc.getID()); builder.setRef(vc.getReference().getBaseString()); for (Allele all : vc.getAlternateAlleles()) builder.getAlt().add(all.getBaseString()); builder.getFilter().addAll(vc.getFilters()); int an = vc.getAttributeAsInt("AN", 0); builder.setChromCount(an); ArrayList<Integer> counts = Lists.newArrayList(vc.getAttributeAsList("AC").stream() .map(x -> Integer.parseInt((String) x)).collect(Collectors.toList())); builder.setAlleleCounts(counts); builder.setAlleleFrequencies( Lists.newArrayList(counts.stream().map(x -> (1.0 * x) / an).collect(Collectors.toList()))); return builder.build(); } @Override UK10KRecord convert(VariantContext vc); }### Answer:
@Test public void test() { UK10KVariantContextToRecordConverter converter = new UK10KVariantContextToRecordConverter(); VariantContext vc = vcfReader.iterator().next(); UK10KRecord record = converter.convert(vc); Assert.assertEquals( "UK10KRecord [chrom=1, pos=28589, id=., ref=T, alt=[TTGG], filter=[], " + "altAlleleCounts=[7226], chromCount=7562, altAlleleFrequencies=[0.9555673102353874]]", record.toString()); } |
### Question:
DBSNPInfoFactory { public DBSNPInfo build(VCFHeader vcfHeader) { String fileDate = vcfHeader.getMetaDataLine("fileDate").getValue(); String source = vcfHeader.getMetaDataLine("source").getValue(); int dbSNPBuildID = Integer.parseInt(vcfHeader.getMetaDataLine("dbSNP_BUILD_ID").getValue()); String reference = vcfHeader.getMetaDataLine("reference").getValue(); String phasing = vcfHeader.getMetaDataLine("phasing").getValue(); return new DBSNPInfo(fileDate, source, dbSNPBuildID, reference, phasing); } DBSNPInfo build(VCFHeader vcfHeader); }### Answer:
@Test public void test() { DBSNPInfoFactory factory = new DBSNPInfoFactory(); DBSNPInfo info = factory.build(vcfReader.getFileHeader()); Assert.assertEquals("20160408", info.getFileDate()); Assert.assertEquals("dbSNP", info.getSource()); Assert.assertEquals(147, info.getDbSNPBuildID()); Assert.assertEquals("GRCh37.p13", info.getReference()); Assert.assertEquals("partial", info.getPhasing()); } |
### Question:
ProteinFrameshift extends ProteinChange { public static ProteinFrameshift buildShort(boolean onlyPredicted, String wtAA, int position) { return new ProteinFrameshift(onlyPredicted, ProteinPointLocation.build(wtAA, position), null, LEN_SHORT); } ProteinFrameshift(boolean onlyPredicted, ProteinPointLocation position, String targetAA, int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, String wtAA, int position, String targetAA,
int shiftLength); static ProteinFrameshift build(boolean onlyPredicted, ProteinPointLocation position, String targetAA,
int shiftLength); static ProteinFrameshift buildShort(boolean onlyPredicted, String wtAA, int position); static ProteinFrameshift buildShort(boolean onlyPredicted, ProteinPointLocation position); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, String wtAA, int position,
String targetAA); static ProteinFrameshift buildWithoutTerminal(boolean onlyPredicted, ProteinPointLocation position,
String targetAA); boolean isShort(); boolean isNoTerminalFrameshfit(); ProteinPointLocation getPosition(); String getTargetAA(); int getShiftLength(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); static final int LEN_NO_TER; static final int LEN_SHORT; }### Answer:
@Test public void testConstructShortFrameshift() { Assert.assertEquals(shortFrameshift, ProteinFrameshift.buildShort(false, position)); } |
### Question:
VariantNormalizer { public VariantDescription normalizeVariant(VariantDescription desc) { final VariantDescription shifted = shiftLeft(desc); return trimBasesLeft(shifted, 0); } VariantNormalizer(String fastaPath); VariantDescription normalizeVariant(VariantDescription desc); VariantDescription normalizeInsertion(VariantDescription desc); }### Answer:
@Test public void testSNV() { VariantDescription descIn = new VariantDescription("braf", 19, "G", "C"); VariantDescription descOut = normalizer.normalizeVariant(descIn); Assert.assertEquals("braf", descOut.getChrom()); Assert.assertEquals(19, descOut.getPos()); Assert.assertEquals("G", descOut.getRef()); Assert.assertEquals("C", descOut.getAlt()); }
@Test public void testOnNormalInsertion() { VariantDescription descIn = new VariantDescription("braf", 19, "G", "GCT"); VariantDescription descOut = normalizer.normalizeVariant(descIn); Assert.assertEquals("braf", descOut.getChrom()); Assert.assertEquals(19, descOut.getPos()); Assert.assertEquals("", descOut.getRef()); Assert.assertEquals("CT", descOut.getAlt()); }
@Test public void testShiftDeletionLeft() { VariantDescription descIn = new VariantDescription("braf", 180, "TGT", "T"); VariantDescription descOut = normalizer.normalizeVariant(descIn); Assert.assertEquals("braf", descOut.getChrom()); Assert.assertEquals(175, descOut.getPos()); Assert.assertEquals("TG", descOut.getRef()); Assert.assertEquals("", descOut.getAlt()); }
@Test public void testShiftInsertionLeft() { VariantDescription descIn = new VariantDescription("braf", 180, "T", "TGT"); VariantDescription descOut = normalizer.normalizeVariant(descIn); Assert.assertEquals("braf", descOut.getChrom()); Assert.assertEquals(175, descOut.getPos()); Assert.assertEquals("", descOut.getRef()); Assert.assertEquals("TG", descOut.getAlt()); } |
### Question:
GenomeRegionSequenceExtractor { public String load(GenomeInterval region) { region = region.withStrand(Strand.FWD); String contigName = region.getRefDict().getContigIDToName().get(region.getChr()); contigName = mapContigToFasta(contigName); ReferenceSequence seq = indexedFile.getSubsequenceAt(contigName, region.getBeginPos() + 1, region.getEndPos()); return new String(seq.getBases()); } GenomeRegionSequenceExtractor(JannovarData jannovarData, IndexedFastaSequenceFile indexedFile); String load(GenomeInterval region); }### Answer:
@Test public void testLoadGenomeInterval() { GenomeRegionSequenceExtractor extractor = new GenomeRegionSequenceExtractor(jannovarData, this.indexedFile); GenomeInterval region = new GenomeInterval(new GenomePosition(jannovarData.getRefDict(), Strand.FWD, 1, 99), 51); String seq = extractor.load(region); Assert.assertEquals("CTTTAGGCCTGGGAATCAGGAGTGCTATGACAATTTCCTCCAAAGTGGAGA", seq); } |
### Question:
ProteinExtension extends ProteinChange { public static ProteinExtension build(boolean onlyPredicted, String wtAA, int pos, String targetAA, int shift) { return build(onlyPredicted, ProteinPointLocation.build(wtAA, pos), targetAA, shift); } ProteinExtension(boolean onlyPredicted, ProteinPointLocation position, String targetAA, int shift); static ProteinExtension build(boolean onlyPredicted, String wtAA, int pos, String targetAA, int shift); static ProteinExtension build(boolean onlyPredicted, ProteinPointLocation position, String targetAA,
int shift); static ProteinExtension buildWithoutTerminal(boolean onlyPredicted, String wtAA, int pos, String targetAA); static ProteinExtension buildWithoutTerminal(boolean onlyPredicted, ProteinPointLocation position,
String targetAA); ProteinPointLocation getPosition(); String getTargetAA(); int getShift(); boolean isNoTerminalExtension(); @Override String toHGVSString(AminoAcidCode code); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override ProteinChange withOnlyPredicted(boolean onlyPredicted); static final int LEN_NO_TER; }### Answer:
@Test public void testBuildNormalExtension() { Assert.assertEquals(normalExtension, ProteinExtension.build(false, position, "T", 23)); } |
### Question:
PhoneUtil { public static String hiddenMiddlePhoneNum(String phoneNumber) throws IOException { if (!isPhoneNumber(phoneNumber)) { throw new IOException("phoneNumber invalid"); } return phoneNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); } @SuppressLint("HardwareIds") static String getIMEI(Context context); @SuppressLint("HardwareIds") static String getIMSI(Context context); static String hiddenMiddlePhoneNum(String phoneNumber); static boolean isPhoneNumber(String phoneNumber); }### Answer:
@Test public void hiddenMiddlePhoneNum() throws Exception { String hiddenPhoneNumber = PhoneUtil.hiddenMiddlePhoneNum("13634429866"); Assert.assertEquals("", "136****9866", hiddenPhoneNumber); }
@Test(expected = IOException.class) public void testErrorPhoneNumber() throws Exception { String hiddenPhoneNumber = PhoneUtil.hiddenMiddlePhoneNum("1363442986"); Assert.assertEquals("", "136****986", hiddenPhoneNumber); } |
### Question:
PhoneUtil { public static boolean isPhoneNumber(String phoneNumber) { if (phoneNumber == null || phoneNumber.trim().length() != 11) { return false; } Pattern p = Pattern.compile("^[1][0-9]{10}$"); Matcher m = p.matcher(phoneNumber); return m.matches(); } @SuppressLint("HardwareIds") static String getIMEI(Context context); @SuppressLint("HardwareIds") static String getIMSI(Context context); static String hiddenMiddlePhoneNum(String phoneNumber); static boolean isPhoneNumber(String phoneNumber); }### Answer:
@Test public void isPhoneNumber() throws Exception { boolean phoneNumber = PhoneUtil.isPhoneNumber("13634429866"); Assert.assertTrue(phoneNumber); } |
### Question:
ImageUtil { public static void toFile(String oldFile, String newFile, ImageParamDTO params) throws IOException { if (StringUtils.isBlank(oldFile) || StringUtils.isBlank(newFile)) { logger.error("原文件名或目标文件名为空"); return; } Thumbnails.Builder builder = Thumbnails.of(oldFile); fillBuilderWithParams(builder, params); if (null == builder) { return; } builder.toFile(newFile); } static void toFile(String oldFile, String newFile, ImageParamDTO params); static BufferedImage toBufferedImage(String oldFile, ImageParamDTO params); static OutputStream toOutputStream(InputStream input, OutputStream output, ImageParamDTO params); static String getContentType(byte[] content); static final InputStream bytes2InputStream(byte[] buf); static final byte[] inputStream2bytes(InputStream inStream); }### Answer:
@Test public void testToFile() throws IOException { final String oldFile = System.getProperty("user.dir") + "/src/test/resources/images/lion2.jpg"; final String newFile = System.getProperty("user.dir") + "/src/test/resources/images/lion2_watermark"; final String warterFile = System.getProperty("user.dir") + "/src/test/resources/images/wartermark.png"; ImageParamDTO params = new ImageParamDTO(); params.setFormat("png"); params.setWaterMark(new ImageParamDTO.WaterMark(9, warterFile, 0.6f)); ImageUtil.toFile(oldFile, newFile, params); } |
### Question:
ImageUtil { public static BufferedImage toBufferedImage(String oldFile, ImageParamDTO params) throws IOException { if (StringUtils.isBlank(oldFile)) { logger.error("原文件名或目标文件名为空"); return null; } Thumbnails.Builder builder = Thumbnails.of(oldFile); fillBuilderWithParams(builder, params); if (null == builder) { return null; } return builder.asBufferedImage(); } static void toFile(String oldFile, String newFile, ImageParamDTO params); static BufferedImage toBufferedImage(String oldFile, ImageParamDTO params); static OutputStream toOutputStream(InputStream input, OutputStream output, ImageParamDTO params); static String getContentType(byte[] content); static final InputStream bytes2InputStream(byte[] buf); static final byte[] inputStream2bytes(InputStream inStream); }### Answer:
@Test public void testToBufferedImage() throws IOException { final String oldFile = System.getProperty("user.dir") + "/src/test/resources/images/lion2.jpg"; ImageParamDTO params = new ImageParamDTO(); params.setWidth(64); params.setHeight(64); BufferedImage bufferedImage = ImageUtil.toBufferedImage(oldFile, params); Assert.assertNotNull(bufferedImage); } |
### Question:
ImageUtil { public static String getContentType(byte[] content) throws MagicParseException, MagicException, MagicMatchNotFoundException { MagicMatch match = Magic.getMagicMatch(content); return match.getMimeType(); } static void toFile(String oldFile, String newFile, ImageParamDTO params); static BufferedImage toBufferedImage(String oldFile, ImageParamDTO params); static OutputStream toOutputStream(InputStream input, OutputStream output, ImageParamDTO params); static String getContentType(byte[] content); static final InputStream bytes2InputStream(byte[] buf); static final byte[] inputStream2bytes(InputStream inStream); }### Answer:
@Test public void testGetContentType() throws MagicParseException, MagicException, MagicMatchNotFoundException, IOException { final String oldFile = System.getProperty("user.dir") + "/src/test/resources/images/lion2.jpg"; byte[] bytes = toBytes(new File(oldFile)); String type = ImageUtil.getContentType(bytes); Assert.assertEquals("image/jpeg", type); } |
### Question:
QRCodeUtil { public static void encode(String content, BarcodeParamDTO paramDTO) throws WriterException, IOException { BitMatrix bitMatrix = new MultiFormatWriter().encode(content, paramDTO.getBarcodeFormat(), paramDTO.getWidth(), paramDTO.getHeight(), paramDTO.getEncodeHints()); Path path = FileSystems.getDefault().getPath(paramDTO.getFilepath()); MatrixToImageWriter.writeToPath(bitMatrix, paramDTO.getImageFormat(), path); } static void encode(String content, BarcodeParamDTO paramDTO); static String decode(BarcodeParamDTO paramDTO); }### Answer:
@Test public void test01() throws IOException, WriterException { QRCodeUtil.encode(jsonContent, paramDTO); File f = new File(qrcodeFile); Assert.assertTrue(f.exists()); } |
### Question:
QRCodeUtil { public static String decode(BarcodeParamDTO paramDTO) { try { BufferedImage bufferedImage = ImageIO.read(new FileInputStream(paramDTO.getFilepath())); LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap bitmap = new BinaryBitmap(binarizer); Result result = new MultiFormatReader().decode(bitmap, paramDTO.getDecodeHints()); return result.getText(); } catch (Exception e) { e.printStackTrace(); return null; } } static void encode(String content, BarcodeParamDTO paramDTO); static String decode(BarcodeParamDTO paramDTO); }### Answer:
@Test public void test02() { String expect = "{\"gender\":\"MALE\",\"name\":{\"last\":\"Zhang\",\"first\":\"Peng\"},\"email\":\"[email protected]\"}"; String content = QRCodeUtil.decode(paramDTO); Assert.assertEquals(expect, content); } |
### Question:
VelocityUtil { public static String getMergeOutput(VelocityContext context, String templateName) { Template template = velocityEngine.getTemplate(templateName); StringWriter sw = new StringWriter(); template.merge(context, sw); String output = sw.toString(); try { sw.close(); } catch (IOException e) { e.printStackTrace(); } return output; } static String getMergeOutput(VelocityContext context, String templateName); }### Answer:
@Test public void test() { VelocityContext context = new VelocityContext(); context.put("name", "Victor Zhang"); context.put("project", "Velocity"); System.out.println(VelocityUtil.getMergeOutput(context, "template/hello.vm")); } |
### Question:
StringUtils { public static String join(CharSequence delimiter, Iterable values) { StringBuilder sb = new StringBuilder(); Iterator<?> it = values.iterator(); if (it.hasNext()) { sb.append(it.next()); while (it.hasNext()) { sb.append(delimiter); sb.append(it.next()); } } return sb.toString(); } static String join(CharSequence delimiter, Iterable values); }### Answer:
@Test public void testJoin() throws Exception { String result = StringUtils.join(", ", asList(1, 2, 3, 4, 5)); Assert.assertEquals(result, "1, 2, 3, 4, 5"); } |
### Question:
Characteristics { public boolean isLegacyDevice() { int hardwareLevel = cameraCharacteristics .get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); return hardwareLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; } Characteristics(CameraCharacteristics cameraCharacteristics); boolean isFrontFacingLens(); boolean isFlashAvailable(); boolean isFixedFocusLens(); boolean isLegacyDevice(); int getSensorOrientation(); int[] autoExposureModes(); int[] autoFocusModes(); Set<Size> getJpegOutputSizes(); Set<Size> getSurfaceOutputSizes(); Set<Range<Integer>> getTargetFpsRanges(); Range<Integer> getSensorSensitivityRange(); }### Answer:
@Test public void isLegacyDevice() throws Exception { given(cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)) .willReturn(CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY); boolean isLegacyDevice = testee.isLegacyDevice(); assertTrue(isLegacyDevice); } |
### Question:
Characteristics { public int getSensorOrientation() { return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); } Characteristics(CameraCharacteristics cameraCharacteristics); boolean isFrontFacingLens(); boolean isFlashAvailable(); boolean isFixedFocusLens(); boolean isLegacyDevice(); int getSensorOrientation(); int[] autoExposureModes(); int[] autoFocusModes(); Set<Size> getJpegOutputSizes(); Set<Size> getSurfaceOutputSizes(); Set<Range<Integer>> getTargetFpsRanges(); Range<Integer> getSensorSensitivityRange(); }### Answer:
@Test public void sensorOrientation() throws Exception { given(cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION)) .willReturn(90); int sensorOrientation = testee.getSensorOrientation(); assertEquals(90, sensorOrientation); } |
### Question:
Characteristics { public int[] autoExposureModes() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES); } Characteristics(CameraCharacteristics cameraCharacteristics); boolean isFrontFacingLens(); boolean isFlashAvailable(); boolean isFixedFocusLens(); boolean isLegacyDevice(); int getSensorOrientation(); int[] autoExposureModes(); int[] autoFocusModes(); Set<Size> getJpegOutputSizes(); Set<Size> getSurfaceOutputSizes(); Set<Range<Integer>> getTargetFpsRanges(); Range<Integer> getSensorSensitivityRange(); }### Answer:
@Test public void autoExposureModes() throws Exception { int[] availableExposures = { CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH, CameraMetadata.CONTROL_AE_MODE_OFF }; given(cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES)) .willReturn(availableExposures); int[] autoExposureModes = testee.autoExposureModes(); assertEquals(availableExposures, autoExposureModes); } |
### Question:
Characteristics { public int[] autoFocusModes() { return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES); } Characteristics(CameraCharacteristics cameraCharacteristics); boolean isFrontFacingLens(); boolean isFlashAvailable(); boolean isFixedFocusLens(); boolean isLegacyDevice(); int getSensorOrientation(); int[] autoExposureModes(); int[] autoFocusModes(); Set<Size> getJpegOutputSizes(); Set<Size> getSurfaceOutputSizes(); Set<Range<Integer>> getTargetFpsRanges(); Range<Integer> getSensorSensitivityRange(); }### Answer:
@Test public void autoFocusModes() throws Exception { int[] availableExposures = { CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_VIDEO, CameraMetadata.CONTROL_AF_MODE_EDOF, CameraMetadata.CONTROL_AF_MODE_OFF }; given(cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES)) .willReturn(availableExposures); int[] autoFocusModes = testee.autoFocusModes(); assertEquals(availableExposures, autoFocusModes); } |
### Question:
CameraSelector { @NonNull public String findCameraId(LensPosition lensPosition) { try { return getCameraIdUnsafe(lensPosition); } catch (CameraAccessException e) { throw new CameraException(e); } } CameraSelector(android.hardware.camera2.CameraManager manager); @NonNull String findCameraId(LensPosition lensPosition); }### Answer:
@Test(expected = CameraException.class) public void cameraNotAvailable() throws Exception { given(manager.getCameraIdList()) .willThrow(new CameraAccessException(CAMERA_ERROR)); testee.findCameraId(LensPosition.EXTERNAL); }
@Test(expected = CameraException.class) public void noCameraFound() throws Exception { given(manager.getCameraIdList()) .willReturn(new String[]{"0"}); testee.findCameraId(LensPosition.EXTERNAL); }
@Test public void getFrontCamera() throws Exception { given(manager.getCameraIdList()) .willReturn(new String[]{"0", "1"}); String cameraId = testee.findCameraId(LensPosition.FRONT); assertEquals("1", cameraId); } |
### Question:
PendingResult { public <R> PendingResult<R> transform(@NonNull final Transformer<T, R> transformer) { FutureTask<R> transformTask = new FutureTask<>(new Callable<R>() { @Override public R call() throws Exception { return transformer.transform( future.get() ); } }); executor.execute(transformTask); return new PendingResult<>( transformTask, executor ); } PendingResult(Future<T> future,
Executor executor); static PendingResult<T> fromFuture(@NonNull Future<T> future); PendingResult<R> transform(@NonNull final Transformer<T, R> transformer); T await(); R adapt(@NonNull Adapter<T, R> adapter); void whenAvailable(@NonNull final Callback<T> callback); void whenDone(@NonNull final Callback<T> callback); }### Answer:
@Test public void transform() throws Exception { given(transformer.transform(RESULT)) .willReturn(123); Integer result = testee.transform(transformer) .await(); assertEquals( Integer.valueOf(123), result ); } |
### Question:
RendererParametersProvider implements RendererParametersOperator { @Override public RendererParameters getRendererParameters() { return new RendererParameters( parametersProvider.getPreviewSize(), orientationManager.getPhotoOrientation() ); } RendererParametersProvider(ParametersProvider parametersProvider,
OrientationManager orientationManager); @Override RendererParameters getRendererParameters(); }### Answer:
@Test public void getParameters() throws Exception { Size size = new Size(1920, 1080); int sensorOrientation = 90; given(parametersProvider.getPreviewSize()) .willReturn(size); given(orientationManager.getPhotoOrientation()) .willReturn(sensorOrientation); RendererParameters rendererParameters = testee.getRendererParameters(); assertEquals( new RendererParameters( size, sensorOrientation ), rendererParameters ); } |
### Question:
Request { static CaptureRequest create(CaptureRequestBuilder builder) throws CameraAccessException { return new Request( builder.cameraDevice, builder.requestTemplate, builder.surfaces, builder.shouldTriggerAutoFocus, builder.triggerPrecaptureExposure, builder.cancelPrecaptureExposure, builder.flash, builder.shouldSetExposureMode, builder.focus, builder.previewFpsRange, builder.sensorSensitivity, builder.jpegQuality ) .build(); } private Request(CameraDevice cameraDevice,
int requestTemplate,
List<Surface> surfaces,
boolean shouldTriggerAutoFocus,
boolean triggerPrecaptureExposure,
boolean cancelPrecaptureExposure,
Flash flash, boolean shouldSetExposureMode,
FocusMode focus,
Range<Integer> previewFpsRange,
Integer sensorSensitivity,
Integer jpegQuality); }### Answer:
@Test public void stillCapture_setCaptureIntent() throws Exception { CaptureRequestBuilder request = simpleRequest(); Request.create(request); verify(builder) .set(CaptureRequest.CONTROL_CAPTURE_INTENT, CameraMetadata.CONTROL_CAPTURE_INTENT_STILL_CAPTURE); verify(builder) .set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); }
@Test public void stillCapture_notSetCaptureIntent() throws Exception { CaptureRequestBuilder request = CaptureRequestBuilder .create( cameraDevice, CameraDevice.TEMPLATE_PREVIEW ) .into(surface); Request.create(request); verify(builder, never()) .set(CaptureRequest.CONTROL_CAPTURE_INTENT, CameraMetadata.CONTROL_CAPTURE_INTENT_STILL_CAPTURE); verify(builder, never()) .set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); } |
### Question:
CaptureRequestBuilder { CaptureRequest build() throws CameraAccessException { validate(); return Request.create(this); } private CaptureRequestBuilder(CameraDevice cameraDevice, @RequestTemplate int requestTemplate); }### Answer:
@Test public void onlyMandatoryParameters() throws Exception { CaptureRequestBuilder builder = builderWithMandatoryArguments(); CaptureRequest result = builder.build(); assertNotNull(result); assertEquals(Collections.singletonList(surface), builder.surfaces); assertEquals(cameraDevice, builder.cameraDevice); assertEquals(CameraDevice.TEMPLATE_STILL_CAPTURE, builder.requestTemplate); } |
### Question:
ParametersProvider implements ParametersOperator { public Flash getFlash() { return getSelectedParameters().getValue(FLASH); } @Override void updateParameters(Parameters selectedParameters); Flash getFlash(); FocusMode getFocus(); Size getStillCaptureSize(); Size getPreviewSize(); float getStillCaptureAspectRatio(); Range<Integer> getPreviewFpsRange(); Integer getSensorSensitivity(); Integer getJpegQuality(); }### Answer:
@Test public void getFlash() throws Exception { given(parameters.getValue(Parameters.Type.FLASH)) .willReturn(Flash.OFF); testee.updateParameters(parameters); Flash flash = testee.getFlash(); assertEquals(Flash.OFF, flash); } |
### Question:
PendingResult { public <R> R adapt(@NonNull Adapter<T, R> adapter) { return adapter.adapt(future); } PendingResult(Future<T> future,
Executor executor); static PendingResult<T> fromFuture(@NonNull Future<T> future); PendingResult<R> transform(@NonNull final Transformer<T, R> transformer); T await(); R adapt(@NonNull Adapter<T, R> adapter); void whenAvailable(@NonNull final Callback<T> callback); void whenDone(@NonNull final Callback<T> callback); }### Answer:
@Test public void adapt() throws Exception { given(adapter.adapt(FUTURE)) .willReturn(123); int result = testee.adapt(adapter); verify(adapter).adapt(FUTURE); assertEquals(123, result); } |
### Question:
ParametersProvider implements ParametersOperator { public FocusMode getFocus() { return getSelectedParameters().getValue(FOCUS_MODE); } @Override void updateParameters(Parameters selectedParameters); Flash getFlash(); FocusMode getFocus(); Size getStillCaptureSize(); Size getPreviewSize(); float getStillCaptureAspectRatio(); Range<Integer> getPreviewFpsRange(); Integer getSensorSensitivity(); Integer getJpegQuality(); }### Answer:
@Test public void getFocus() throws Exception { given(parameters.getValue(Parameters.Type.FOCUS_MODE)) .willReturn(FocusMode.CONTINUOUS_FOCUS); testee.updateParameters(parameters); FocusMode focusMode = testee.getFocus(); assertEquals(FocusMode.CONTINUOUS_FOCUS, focusMode); } |
### Question:
ParametersProvider implements ParametersOperator { public Size getPreviewSize() { return getSelectedParameters().getValue(PREVIEW_SIZE); } @Override void updateParameters(Parameters selectedParameters); Flash getFlash(); FocusMode getFocus(); Size getStillCaptureSize(); Size getPreviewSize(); float getStillCaptureAspectRatio(); Range<Integer> getPreviewFpsRange(); Integer getSensorSensitivity(); Integer getJpegQuality(); }### Answer:
@Test public void getPreviewSize() throws Exception { given(parameters.getValue(Parameters.Type.PREVIEW_SIZE)) .willReturn(new Size(1920, 1080)); testee.updateParameters(parameters); Size previewSize = testee.getPreviewSize(); assertEquals(new Size(1920, 1080), previewSize); } |
### Question:
OrientationUtils { public static int toClosestRightAngle(int degrees) { boolean roundUp = degrees % 90 > 45; int roundAppModifier = roundUp ? 1 : 0; return (((degrees / 90) + roundAppModifier) * 90) % 360; } static int toClosestRightAngle(int degrees); static int computeDisplayOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); static int computeImageOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); }### Answer:
@Test public void toClosestRightAngle_0() throws Exception { assertEquals( 0, OrientationUtils.toClosestRightAngle(5) ); }
@Test public void toClosestRightAngle_90() throws Exception { assertEquals( 90, OrientationUtils.toClosestRightAngle(60) ); }
@Test public void toClosestRightAngle_180() throws Exception { assertEquals( 180, OrientationUtils.toClosestRightAngle(190) ); }
@Test public void toClosestRightAngle_270() throws Exception { assertEquals( 270, OrientationUtils.toClosestRightAngle(269) ); }
@Test public void toClosestRightAngle_360() throws Exception { assertEquals( 0, OrientationUtils.toClosestRightAngle(359) ); } |
### Question:
OrientationUtils { public static int computeDisplayOrientation(int screenRotationDegrees, int cameraRotationDegrees, boolean cameraIsMirrored) { int degrees = OrientationUtils.toClosestRightAngle(screenRotationDegrees); if (cameraIsMirrored) { degrees = (cameraRotationDegrees + degrees) % 360; degrees = (360 - degrees) % 360; } else { degrees = (cameraRotationDegrees - degrees + 360) % 360; } return degrees; } static int toClosestRightAngle(int degrees); static int computeDisplayOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); static int computeImageOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); }### Answer:
@Test public void computeDisplayOrientation_Phone_Portrait_FrontCamera() throws Exception { int screenOrientation = 0; int cameraOrientation = 270; int result = OrientationUtils.computeDisplayOrientation( screenOrientation, cameraOrientation, true ); assertEquals(90, result); }
@Test public void computeDisplayOrientation_Phone_Landscape_FrontCamera() throws Exception { int screenOrientation = 270; int cameraOrientation = 270; int result = OrientationUtils.computeDisplayOrientation( screenOrientation, cameraOrientation, true ); assertEquals(180, result); }
@Test public void computeDisplayOrientation_Phone_Portrait_BackCamera() throws Exception { int screenOrientation = 0; int cameraOrientation = 90; int result = OrientationUtils.computeDisplayOrientation( screenOrientation, cameraOrientation, false ); assertEquals(90, result); }
@Test public void computeDisplayOrientation_Phone_Landscape_BackCamera() throws Exception { int screenOrientation = 270; int cameraOrientation = 90; int result = OrientationUtils.computeDisplayOrientation( screenOrientation, cameraOrientation, false ); assertEquals(180, result); } |
### Question:
PendingResult { public T await() throws ExecutionException, InterruptedException { return future.get(); } PendingResult(Future<T> future,
Executor executor); static PendingResult<T> fromFuture(@NonNull Future<T> future); PendingResult<R> transform(@NonNull final Transformer<T, R> transformer); T await(); R adapt(@NonNull Adapter<T, R> adapter); void whenAvailable(@NonNull final Callback<T> callback); void whenDone(@NonNull final Callback<T> callback); }### Answer:
@Test public void await() throws Exception { String result = testee.await(); assertEquals( RESULT, result ); } |
### Question:
OrientationUtils { public static int computeImageOrientation(int screenRotationDegrees, int cameraRotationDegrees, boolean cameraIsMirrored) { int rotation; if (cameraIsMirrored) { rotation = -(screenRotationDegrees + cameraRotationDegrees); } else { rotation = screenRotationDegrees - cameraRotationDegrees; } return (rotation + 360 + 360) % 360; } static int toClosestRightAngle(int degrees); static int computeDisplayOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); static int computeImageOrientation(int screenRotationDegrees,
int cameraRotationDegrees,
boolean cameraIsMirrored); }### Answer:
@Test public void computeImageOrientation_Phone_Portrait_FrontCamera() throws Exception { int screenOrientation = 0; int cameraOrientation = 270; int result = OrientationUtils.computeImageOrientation( screenOrientation, cameraOrientation, true ); assertEquals(90, result); }
@Test public void computeImageOrientation_Phone_Landscape_FrontCamera() throws Exception { int screenOrientation = 270; int cameraOrientation = 270; int result = OrientationUtils.computeImageOrientation( screenOrientation, cameraOrientation, true ); assertEquals(180, result); }
@Test public void computeImageOrientation_Phone_Portrait_BackCamera() throws Exception { int screenOrientation = 0; int cameraOrientation = 90; int result = OrientationUtils.computeImageOrientation( screenOrientation, cameraOrientation, false ); assertEquals(270, result); }
@Test public void computeImageOrientation_Phone_Landscape_BackCamera() throws Exception { int screenOrientation = 270; int cameraOrientation = 90; int result = OrientationUtils.computeImageOrientation( screenOrientation, cameraOrientation, false ); assertEquals(180, result); } |
### Question:
ParametersConverter { public CameraParametersDecorator toPlatformParameters(Parameters parameters, CameraParametersDecorator output) { for (Parameters.Type storedType : parameters.storedTypes()) { applyParameter( storedType, parameters, output ); } return output; } CameraParametersDecorator toPlatformParameters(Parameters parameters,
CameraParametersDecorator output); Parameters fromPlatformParameters(CameraParametersDecorator platformParameters); }### Answer:
@Test public void returnSameValue() throws Exception { Parameters input = new Parameters(); CameraParametersDecorator result = testee.toPlatformParameters( input, outputParameters ); assertSame( result, outputParameters ); }
@Test public void setFocusMode() throws Exception { Parameters input = new Parameters(); input.putValue( Parameters.Type.FOCUS_MODE, FocusMode.AUTO ); testee.toPlatformParameters( input, outputParameters ); verify(outputParameters).setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); }
@Test public void setFlash() throws Exception { Parameters input = new Parameters(); input.putValue( Parameters.Type.FLASH, Flash.TORCH ); testee.toPlatformParameters( input, outputParameters ); verify(outputParameters).setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); }
@Test public void setPictureSize() throws Exception { Parameters input = new Parameters(); input.putValue( Parameters.Type.PICTURE_SIZE, new Size(10, 20) ); testee.toPlatformParameters( input, outputParameters ); verify(outputParameters).setPictureSize(10, 20); }
@Test public void setPreviewSize() throws Exception { Parameters input = new Parameters(); input.putValue( Parameters.Type.PREVIEW_SIZE, new Size(10, 20) ); testee.toPlatformParameters( input, outputParameters ); verify(outputParameters).setPreviewSize(10, 20); } |
### Question:
Fotoapparat { public void start() { ensureNotStarted(); started = true; startCamera(); configurePreviewStream(); updateOrientationRoutine.start(); } Fotoapparat(StartCameraRoutine startCameraRoutine,
StopCameraRoutine stopCameraRoutine,
UpdateOrientationRoutine updateOrientationRoutine,
ConfigurePreviewStreamRoutine configurePreviewStreamRoutine,
CapabilitiesProvider capabilitiesProvider,
CurrentParametersProvider parametersProvider,
TakePictureRoutine takePictureRoutine,
AutoFocusRoutine autoFocusRoutine,
CheckAvailabilityRoutine checkAvailabilityRoutine,
UpdateParametersRoutine updateParametersRoutine,
UpdateZoomLevelRoutine updateZoomLevelRoutine,
Executor executor); static FotoapparatBuilder with(Context context); boolean isAvailable(); CapabilitiesResult getCapabilities(); ParametersResult getCurrentParameters(); PhotoResult takePicture(); Fotoapparat autoFocus(); PendingResult<FocusResult> focus(); void updateParameters(@NonNull final UpdateRequest updateRequest); void setZoom(@FloatRange(from = 0f, to = 1f) final float zoomLevel); void start(); void stop(); }### Answer:
@Test public void start() throws Exception { testee.start(); InOrder inOrder = inOrder( startCameraRoutine, updateOrientationRoutine, configurePreviewStreamRoutine ); inOrder.verify(startCameraRoutine).run(); inOrder.verify(configurePreviewStreamRoutine).run(); inOrder.verify(updateOrientationRoutine).start(); }
@Test(expected = IllegalStateException.class) public void start_SecondTime() throws Exception { testee.start(); testee.start(); } |
### Question:
CameraParametersDecorator { @NonNull public Set<Integer> getSensorSensitivityValues() { String[] rawValues = extractRawCameraValues(RAW_ISO_SUPPORTED_VALUES_KEYS); return convertParamsToInts(rawValues); } CameraParametersDecorator(Camera.Parameters cameraParameters); Camera.Parameters asCameraParameters(); boolean isZoomSupported(); List<Size> getSupportedPreviewSizes(); List<Size> getSupportedPictureSizes(); List<String> getSupportedFlashModes(); List<String> getSupportedFocusModes(); List<int[]> getSupportedPreviewFpsRange(); String getFocusMode(); void setFocusMode(String focusMode); String getFlashMode(); void setFlashMode(String flash); Camera.Size getPictureSize(); Camera.Size getPreviewSize(); void setPreviewSize(int width, int height); void setPictureSize(int width, int height); void setPreviewFpsRange(int min, int max); @NonNull Set<Integer> getSensorSensitivityValues(); void setSensorSensitivityValue(int isoValue); int getJpegQuality(); void setJpegQuality(int quality); }### Answer:
@Test public void getSensorSensitivityValues_Available() throws Exception { given(parameters.get(anyString())) .willReturn("400,600,1200"); Set<Integer> isoValues = parametersProvider.getSensorSensitivityValues(); Assert.assertEquals( isoValues, asSet(400, 600, 1200) ); }
@Test public void getSensorSensitivityValues_NotAvailable() throws Exception { given(parameters.get(anyString())) .willReturn(null); Set<Integer> isoValues = parametersProvider.getSensorSensitivityValues(); Assert.assertEquals( isoValues, Collections.<Integer>emptySet() ); } |
### Question:
CameraParametersDecorator { public void setSensorSensitivityValue(int isoValue) { String isoKey = findExistingKey(RAW_ISO_CURRENT_VALUE_KEYS); if (isoKey != null) { cameraParameters.set(isoKey, isoValue); } } CameraParametersDecorator(Camera.Parameters cameraParameters); Camera.Parameters asCameraParameters(); boolean isZoomSupported(); List<Size> getSupportedPreviewSizes(); List<Size> getSupportedPictureSizes(); List<String> getSupportedFlashModes(); List<String> getSupportedFocusModes(); List<int[]> getSupportedPreviewFpsRange(); String getFocusMode(); void setFocusMode(String focusMode); String getFlashMode(); void setFlashMode(String flash); Camera.Size getPictureSize(); Camera.Size getPreviewSize(); void setPreviewSize(int width, int height); void setPictureSize(int width, int height); void setPreviewFpsRange(int min, int max); @NonNull Set<Integer> getSensorSensitivityValues(); void setSensorSensitivityValue(int isoValue); int getJpegQuality(); void setJpegQuality(int quality); }### Answer:
@Test public void setSensorSensitivityValues_Available() throws Exception { given(parameters.get(anyString())) .willReturn("400"); parametersProvider.setSensorSensitivityValue(600); verify(parameters, times(1)).set(anyString(), anyInt()); }
@Test public void setSensorSensitivityValues_NotAvailable() throws Exception { given(parameters.get(anyString())) .willReturn(null); parametersProvider.setSensorSensitivityValue(600); verify(parameters, times(0)).set(anyString(), anyInt()); } |
### Question:
FlashCapability { public static Flash toFlash(String code) { Flash flash = CODE_TO_FLASH.forward().get(code); if (flash == null) { return Flash.OFF; } return flash; } static Flash toFlash(String code); static String toCode(Flash flash); }### Answer:
@Test public void toFlash() throws Exception { Flash flash = FlashCapability.toFlash( Camera.Parameters.FLASH_MODE_AUTO ); assertEquals( Flash.AUTO, flash ); }
@Test public void toFlash_Unknown() throws Exception { Flash flash = FlashCapability.toFlash("whatever"); assertEquals( Flash.OFF, flash ); } |
### Question:
FlashCapability { public static String toCode(Flash flash) { return CODE_TO_FLASH.reversed().get(flash); } static Flash toFlash(String code); static String toCode(Flash flash); }### Answer:
@Test public void toCode() throws Exception { String code = FlashCapability.toCode(Flash.AUTO); assertEquals( Camera.Parameters.FLASH_MODE_AUTO, code ); } |
### Question:
SupressExceptionsParametersOperator implements ParametersOperator { @Override public void updateParameters(Parameters parameters) { try { wrapped.updateParameters(parameters); } catch (Exception e) { logger.log("Unable to set parameters: " + parameters); } } SupressExceptionsParametersOperator(ParametersOperator wrapped,
Logger logger); @Override void updateParameters(Parameters parameters); }### Answer:
@Test public void updateParameters() throws Exception { doThrow(new RuntimeException()) .when(wrapped) .updateParameters(parameters); testee.updateParameters(parameters); verify(wrapped).updateParameters(parameters); } |
### Question:
SwitchOnFailureParametersOperator implements ParametersOperator { @Override public void updateParameters(Parameters parameters) { try { first.updateParameters(parameters); } catch (Exception e) { second.updateParameters(parameters); } } SwitchOnFailureParametersOperator(ParametersOperator first,
ParametersOperator second); @Override void updateParameters(Parameters parameters); }### Answer:
@Test public void firstSucceeds() throws Exception { testee.updateParameters(parameters); verify(first).updateParameters(parameters); verifyZeroInteractions(second); }
@Test public void firstFails() throws Exception { doThrow(new RuntimeException()) .when(first) .updateParameters(parameters); testee.updateParameters(parameters); verify(second).updateParameters(parameters); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.