Need some assistance coding this assembler exercise. I have included the test file. Thank you very much.
package sequencer;
import java.util.List;
public class Assembler {
/**
* Creates a new Assembler containing a list of fragments.
*
* The list is copied into this assembler so that the original list will not
* be modified by the actions of this assembler.
*
* @param fragments
*/
public Assembler(List<Fragment> fragments) {
}
/**
* Returns the current list of fragments this assembler contains.
*
* @return the current list of fragments
*/
public List<Fragment> getFragments() {
return null;
}
/**
* Attempts to perform a single assembly, returning true iff an assembly was
* performed.
*
* This method chooses the best assembly possible, that is, it merges the
* two fragments with the largest overlap, breaking ties between merged
* fragments by choosing the shorter merged fragment.
*
* Merges must have an overlap of at least 1.
*
* After merging two fragments into a new fragment, the new fragment is
* inserted into the list of fragments in this assembler, and the two
* original fragments are removed from the list.
*
* @return true iff an assembly was performed
*/
public boolean assembleOnce() {
return false;
}
/**
* Repeatedly assembles fragments until no more assembly can occur.
*/
public void assembleAll() {
}
}
AssemblerTest.java
package sequencer;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
public class AssemblerTest {
// @Rule
// public Timeout globalTimeout = Timeout.seconds(10);
// 10 seconds
private List<Fragment> one;
private List<Fragment> two;
private List<Fragment> three;
private List<Fragment> dupFullOverlap;
// This method is run before each test, performing
initialization
// on and of objects for the test.
@Before
public void setup() {
one = new
ArrayList<Fragment>();
one.add(new Fragment("GCAT"));
two = new
ArrayList<Fragment>();
two.add(new
Fragment("CATG"));
two.add(new Fragment("GCAT"));
three = new
ArrayList<Fragment>();
three.add(new
Fragment("ACTGTG"));
three.add(new
Fragment("ACACAC"));
three.add(new
Fragment("TGTGGG"));
dupFullOverlap = new
ArrayList<Fragment>();
dupFullOverlap.add(new
Fragment("AAGAA"));
dupFullOverlap.add(new
Fragment("AAGAA"));
}
@Test
public void testValidConstructor() {
Assembler a = new
Assembler(one);
}
@Test
public void testSimpleAssemble() {
Assembler a = new
Assembler(two);
assertTrue(a.assembleOnce());
}
@Test
public void testSimpleAssembleStop() {
Assembler a = new
Assembler(two);
assertTrue(a.assembleOnce());
assertFalse(a.assembleOnce());
}
@Test
public void testCorrectSimpleAssemble() {
Assembler a = new
Assembler(two);
assertTrue(a.assembleOnce());
assertFalse(a.assembleOnce());
assertEquals(Arrays.asList(new
Fragment("GCATG")), a.getFragments());
}
@Test
public void testNoAssemble() {
one.add(new
Fragment("CAGT"));
Assembler a = new
Assembler(one);
assertFalse(a.assembleOnce());
assertEquals(2,
a.getFragments().size());
}
@Test
public void testDuplicateFullOverlapAssemble() {
Assembler a = new
Assembler(dupFullOverlap);
assertTrue(a.assembleOnce());
assertFalse(a.assembleOnce());
assertEquals(Arrays.asList(new
Fragment("AAGAA")), a.getFragments());
}
@Test
public void testCorrectThreeAssembleStepwise() {
Assembler a = new
Assembler(three);
assertEquals(3,
a.getFragments().size());
assertTrue(a.assembleOnce());
assertEquals(2,
a.getFragments().size());
assertTrue(a.assembleOnce());
assertEquals(1,
a.getFragments().size());
assertFalse(a.assembleOnce());
assertEquals(1,
a.getFragments().size());
assertEquals(Arrays.asList(new
Fragment("ACACACTGTGGG")), a.getFragments());
}
@Test
public void testCorrectThreeAssembleAll() {
Assembler a = new
Assembler(three);
a.assembleAll();
assertEquals(Arrays.asList(new
Fragment("ACACACTGTGGG")), a.getFragments());
}
@Test
public void testConstructorArgumentUnharmed() {
List<Fragment> copy = new
ArrayList<Fragment>(three);
Assembler a = new
Assembler(three);
a.assembleOnce();
assertEquals(copy, three);
}
@Test
public void testTiebreaker() {
List<Fragment> l =
new
ArrayList<Fragment>(Arrays.asList(
new
Fragment("GGGAAAC"),
new
Fragment("AAACGGG"),
new
Fragment("CCCGTTTA"),
new
Fragment("TTTAGCCC")));
Assembler a = new
Assembler(l);
a.assembleOnce();
assertTrue(a.getFragments().contains(new
Fragment("GGGAAACGGG")));
}
@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));
}
}
Assembler.java
package sequencer;
import java.util.List;
import java.util.ArrayList;
public class Assembler {
public List<Fragment> Fragments = new
ArrayList<Fragment>();
/**
* Creates a new Assembler containing a list of
fragments.
*
* The list is copied into this assembler so that the
original list
* will not be modified by the actions of this
assembler.
*
* @param fragments
*/
public Assembler(List<Fragment> fragments)
{
for(int i = 0; i <
fragments.size(); i++){
Fragments.add(fragments.get(i));
}
}
/**
* Returns the current list of fragments this assembler
contains.
* @return the current list of fragments
*/
public List<Fragment> getFragments() {
return Fragments;
}
/**
* Attempts to perform a single assembly, returning
true if an assembly was performed.
*
* This method chooses the best assembly possible, that
is,
* it merges the two fragments with the largest
overlap, breaking ties
* between merged fragments by choosing the shorter
merged fragment.
*
* Merges must have an overlap of at least 1.
*
* After merging two fragments into a new fragment, the
new fragment is inserted into
* the list of fragments in this assembler, and the two
original fragments are removed
* from the list.
*
* @return true iff an assembly was performed
*/
public boolean assembleOnce() {
int overlapForMerge = 0;
int biggestOverlap = -1;
Fragment fragmentFront =
null;
Fragment fragmentEnd = null;
Fragment merged = null;
for(int i = 0; i <
Fragments.size(); i ++){
for(int j = 0; j < Fragments.size(); j
++){
if(Fragments.get(i) == null
|| Fragments.get(j) == null){
return
false;
}
if(Fragments.get(i) !=
Fragments.get(j)){
overlapForMerge =
Fragments.get(i).calculateOverlap(Fragments.get(j));
if(overlapForMerge > biggestOverlap){
biggestOverlap = overlapForMerge;
fragmentFront = Fragments.get(i);
fragmentEnd = Fragments.get(j);
}
}
}
}
if(biggestOverlap > 0){
Fragments.remove(fragmentFront);
Fragments.remove(fragmentEnd);
merged =
fragmentFront.mergedWith(fragmentEnd);
Fragments.add(merged);
return
true;
}
else {
return
false;
}
}
/**
* Repeatedly assembles fragments until no more
assembly can occur.
*/
public void assembleAll() {
while(assembleOnce() !=
false){
assembleOnce();
}
}
}
Need some assistance coding this assembler exercise. I have included the test file. Thank you very...
Please help complete the items marked TODO in the code and get the tests to pass: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestIterator { private List<Integer> list; // See the Java List Interface documentation to understand what all the List methods do ... @Before public void setUp() throws Exception { list = new ArrayList<Integer>(); // TODO also try with a...
I need some help fixing this error. I completed the code, just modify it so the error is gone. I had to remove the imports and parts of the test to fit everything public class Scheduler { private List listOfCourses; private List listOfStudents; public Scheduler() { listOfCourses = new ArrayList(); listOfStudents = new ArrayList(); } public void addCourse(Course course) { listOfCourses.add(course); } public List getCourses() { List courseList =...
I am not passing some of the code when i run the testing . PriorityQueue public class PriorityQueue<T extends Comparable<T>> implements IPriorityQueue<T> { private Vector<T> theVector = new Vector<>(0, 1); private int size = 0; @Override public void insert(T element) { theVector.pushBack(element); size++; bubbleUp(); } @Override public T peekTop() throws java.util.NoSuchElementException { if (isEmpty()) { throw new java.util.NoSuchElementException(); } ...
Need help with a number guessing game in java 1) You should store prior guessses in a linked list, and the nodes in the list must follow the order of prior guesses. For example, if the prior guesses are 1000, 2111, 3222 in that order, the nodes must follow the same order 2) You should store the candidate numbers also in a linked list, and the nodes must follow the order of numbers (i.e. from the smallest to the largest)....
I need help with todo line please public class LinkedList { private Node head; public LinkedList() { head = null; } public boolean isEmpty() { return head == null; } public int size() { int count = 0; Node current = head; while (current != null) { count++; current = current.getNext(); } return count; } public void add(int data) { Node newNode = new Node(data); newNode.setNext(head); head = newNode; } public void append(int data) { Node newNode = new Node(data);...
Please help complete the items marked TODO in the code and get the tests to pass: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds) // TODO (optional) refactor to DRY // TODO...
Please help complete the items marked TODO in the code and get the tests to pass: Someone already answered it, but it was incorrect! import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds)...
I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel { private static final int...
Hi, I am having trouble solving the constructor, it requires to ArrayList marks to be a deep copy of the instance variable. I have also provided the J-Unit test I have been provided. import java.util.*; public class GradebookEntry { private String name; private int id; private ArrayList<Double> marks; /** * DO NOT MODIFY */ public String toString() { String result = name+" (ID "+id+")\t"; for(int i=0; i < marks.size(); i++) { /** * display every mark rounded off to two...
Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. A RationalNumber object should have the following methods: public RationalNumber(int numerator, int denominator) Constructs a new rational number to represent the ratio (numerator/denominator). The denominator cannot be 0, so throw an IllegalArgumentException if 0 is passed. public RationalNumber() Constructs a new rational number to represent the ratio (0/1). public int getDenominator() Returns this rational number’s denominator value; for example, if the ratio is (3/5), returns...