### Question:
Fragment implements Iterable<Atom> { int getChainLength() { int length = 0; Atom next = getAtomByLocant(Integer.toString(length + 1)); Atom previous = null; while (next != null){ if (previous != null && previous.getBondToAtom(next) == null){ break; } length++; previous = next; next = getAtomByLocant(Integer.toString(length + 1)); } return length; } Fragment(Element tokenEl);   Fragment(String type); @Override Iterator<Atom> iterator();  }### Answer:
@Test public void testGetChainLength() { assertEquals("No chain", 0, frag.getChainLength()); Atom a1 =new Atom(1, ChemEl.C, frag); a1.addLocant("1"); frag.addAtom(a1); assertEquals("Methane", 1, frag.getChainLength()); Atom a2 =new Atom(2, ChemEl.C, frag); a2.addLocant("2"); frag.addAtom(a2); fm.createBond(frag.getAtomByID(1), frag.getAtomByID(2), 1); assertEquals("ethane", 2, frag.getChainLength()); Atom a3 =new Atom(3, ChemEl.C, frag); a3.addLocant("3"); frag.addAtom(a3); fm.createBond(frag.getAtomByID(2), frag.getAtomByID(3), 1); assertEquals("propane", 3, frag.getChainLength()); Atom a4 =new Atom(4, ChemEl.C, frag); frag.addAtom(a4); a4.addLocant("4"); fm.createBond(frag.getAtomByID(2), frag.getAtomByID(4), 1); assertEquals("isobutane", 3, frag.getChainLength()); fm.removeBond(a2.getBondToAtom(a4)); fm.createBond(a3, a4, 1); assertEquals("butane", 4, frag.getChainLength()); }