Question
I have a code, but it has three test failed. Here are the codes: package sequencer; public class Fragment { private String frag; /** *
I have a code, but it has three test failed.
Here are the codes:
package sequencer;
public class Fragment { private String frag; /** * Creates a new Fragment based upon a String representing a sequence of nucleotides, * containing only the uppercase characters G, C, A and T. * @param nucleotides * @throws IllegalArgumentException if invalid characters are in the sequence of nucleotides */ public Fragment(String nucleotides) throws IllegalArgumentException { boolean k = false;
for(int i = 0; i < nucleotides.length(); i++){
char c = nucleotides.charAt(i); if(c=='A'||c=='G'||c=='C'||c=='T'){ k = true; } else{ k = false; }
if(k == false){ throw new IllegalArgumentException("Does not work");
}
frag = nucleotides;
}
} /** * Returns the length of this fragment. * * @return the length of this fragment */ public int length() { return frag.length(); } /** * Returns a String representation of this fragment, exactly as was passed to the constructor. * * @return a String representation of this fragment */ @Override public String toString() { return frag; } /** * Return true if and only if this fragment contains the same sequence of nucleotides * as another sequence. */ @Override public boolean equals(Object o) { boolean k = true; if(o instanceof Fragment == false){ k = false; }
else{ for(int i = 0; i } return k; } /** * Returns the number of nucleotides of overlap between the end of this fragment and * the start of another fragment, f. * * The largest overlap is found, for example, CAA and AAG have an overlap of 2, not 1. * * @param f the other fragment * @return the number of nucleotides of overlap */ public int calculateOverlap(Fragment f) { int overLap = 0; String underFrag = f.toString(); final int maxlen = Integer.min(frag.length(), underFrag.length()); for(int i = 0; i } return overLap; } /** * Returns a new fragment based upon merging this fragment with another fragment f. * * This fragment will be on the left, the other fragment will be on the right; the * fragments will be overlapped as much as possible during the merge. * * @param f the other fragment * @return a new fragment based upon merging this fragment with another fragment */ public Fragment mergedWith(Fragment f) { int val = this.calculateOverlap(f); Fragment g = new Fragment(this.frag+f.frag.substring(val)); return g; } } Here are the failed tests: @Test public void testSequenceHaemoglobinSubunitBeta() { Assembler a = new Assembler(Arrays.asList( new Fragment( "CAAGGTGAACGTGGATGAAGTTGGTGGTGAGGCCCTGGGCAGGCTGCTGGTGGTCTACCCTTGGACCCAGAGGTTCTTTGAGTCCTTTGGGGATCTGTCCACTCCTGATGCTGTTATGGGCAACCCTAAGGTGAAGGCTCA"), new Fragment( "TCACTTTGGCAAAGAATTCACCCCACCAGTGCAGGCTGCCTATCAGAAAGTGGTGGCTGGTGTGGCTAATGCCCTGGCCCACAAGTATCACTAAGCTCGCTTTCTTGCTGTCCAATTTCTATTAAAGGTTCCTT"), new Fragment( "TTTCTTGCTGTCCAATTTCTATTAAAGGTTCCTTTGTTCCCTAAGTCCAACTACTAAACTGGGGGATATTATGAAGGGCCTTGAGCATCTGGATTCTGCCTAATAAAAAACATTTATTTTCATTGC"), new Fragment( "ACTCCTGATGCTGTTATGGGCAACCCTAAGGTGAAGGCTCATGGCAAGAAAGTGCTCGGTGCCTTTAGTGATGGCCTGGCTCACCTGGACAACCTCAAGGGCACCTTTGCCACACTGAGTGAGCTGCACTGTGACAAGCTGCACGTGGATCCTGAGA"), new Fragment( "GCACCTTTGCCACACTGAGTGAGCTGCACTGTGACAAGCTGCACGTGGATCCTGAGAACTTCAGGCTCCTGGGCAACGTGCTGGTCTGTGTGCTGGCCCATCACTTTGGCAAAGAATTCACCCCACCAGTGCAGGCTGCCTATCA"), new Fragment( "ACATTTGCTTCTGACACAACTGTGTTCACTAGCAACCTCAAACAGACACCATGGTGCATCTGACTCCTGAGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGATGAAGTTGGTGGTGAGGCCCTGGGCAGGCTGCT"))); a.assembleAll(); assertEquals(1, a.getFragments().size()); assertEquals(new Fragment("ACATTTGCTTCTGACACAACTGTGTTCACTAGCAACCTCAAACAGACACCATGGTGCATCTGACTCCTGAGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGATGAAGTTGGTGGTGAGGCCCTGGGCAGGCTGCTGGTGGTCTACCCTTGGACCCAGAGGTTCTTTGAGTCCTTTGGGGATCTGTCCACTCCTGATGCTGTTATGGGCAACCCTAAGGTGAAGGCTCATGGCAAGAAAGTGCTCGGTGCCTTTAGTGATGGCCTGGCTCACCTGGACAACCTCAAGGGCACCTTTGCCACACTGAGTGAGCTGCACTGTGACAAGCTGCACGTGGATCCTGAGAACTTCAGGCTCCTGGGCAACGTGCTGGTCTGTGTGCTGGCCCATCACTTTGGCAAAGAATTCACCCCACCAGTGCAGGCTGCCTATCAGAAAGTGGTGGCTGGTGTGGCTAATGCCCTGGCCCACAAGTATCACTAAGCTCGCTTTCTTGCTGTCCAATTTCTATTAAAGGTTCCTTTGTTCCCTAAGTCCAACTACTAAACTGGGGGATATTATGAAGGGCCTTGAGCATCTGGATTCTGCCTAATAAAAAACATTTATTTTCATTGC"), a.getFragments().get(0)); } @Test public void testTiebreaker() { List @Test public void testSameMergeLength() { Fragment f = new Fragment("GCAT"); Fragment g = new Fragment("GCAT"); assertEquals(4, f.calculateOverlap(g)); } How do I fix them?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started