Skip to content

Commit

Permalink
pathwriter uses C and C% for leading alkene carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Apodaca committed Jul 20, 2009
1 parent f371b5f commit 2aa0e27
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 168 deletions.
66 changes: 12 additions & 54 deletions src/com/metamolecular/mx/fingerprint/PathFingerprinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,56 +133,25 @@ public Set<String> paths()

public BitSet getFingerprint(Molecule molecule)
{
paths.clear();
this.bloomFilter = new BloomFilter(1024);
this.writer = new PathWriter(bloomFilter);
bloomFilter.clear();
findAromatics(molecule);

for (int i = 0; i < molecule.countAtoms(); i++)
{
Atom atom = molecule.getAtom(i);
Collection<List<Atom>> rings = ringFinder.findRings(molecule);
findAromatics(molecule, rings);

walker.walk(atom, writer);
}

return bloomFilter.toBitSet();
}

private void findAromatics(Molecule molecule)
{
aromatics.clear();
filter.filterAtoms(molecule, aromatics);

for (Atom atom : aromatics)
{
aromatics.add(atom);
}
recordWalk(molecule);

BitSet walkBits = bloomFilter.toBitSet();
BitSet result = new BitSet(getFingerprintLength());

result.or(walkBits);
writeRingBits(result, rings);

writer.setAromatics(aromatics);
return result;
}

// public BitSet getFingerprint(Molecule molecule)
// {
// bloomFilter.clear();
// Collection<List<Atom>> rings = ringFinder.findRings(molecule);
// findAromatics(molecule, rings);
//
// recordWalk(molecule);
//
// BitSet walkBits = bloomFilter.toBitSet();
// BitSet result = new BitSet(getFingerprintLength());
//
// result.or(walkBits);
//// writeRingBits(result, rings);
//
// return bloomFilter.toBitSet();
// }

private void writeRingBits(BitSet bitset, Collection<List<Atom>> rings)
{
for (List<Atom> ring : rings)
{
// System.out.println("ring: " + (ring.size() - 1));
if (ring.size() < ringBitCount)
{
int index = bloomFilter.getBitArraySize() + (ring.size() - 4);
Expand Down Expand Up @@ -210,16 +179,5 @@ private void findAromatics(Molecule molecule, Collection<List<Atom>> rings)
aromatics.clear();
filter.filterAtoms(molecule.countAtoms(), rings, aromatics);
writer.setAromatics(aromatics);
}// private void findAromatics(Molecule molecule)
// {
// aromatics.clear();
// filter.filterAtoms(molecule, aromatics);
//
// for (Atom atom : aromatics)
// {
// aromatics.add(atom);
// }
//
// writer.setAromatics(aromatics);
// }
}
}
60 changes: 4 additions & 56 deletions src/com/metamolecular/mx/test/PathFingerprinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.metamolecular.mx.model.Atom;
import com.metamolecular.mx.model.DefaultMolecule;
import com.metamolecular.mx.model.Molecule;
import com.metamolecular.mx.model.MoleculeKit;
import com.metamolecular.mx.ring.RingFilter;
import java.util.BitSet;
import junit.framework.TestCase;
Expand Down Expand Up @@ -285,63 +284,12 @@ public void testItMatchesPropaneToAcetone()
assertTrue(match(propane, acetone));
}

// public void testItDoesntMatchCyclooctaneToOctane()
// {
// BitSet cyclooctane = fingerprinter.getFingerprint(createCyclooctane());
// BitSet octane = fingerprinter.getFingerprint(createOctane());
//
// assertFalse(match(cyclooctane, octane));
// }

// public void testItWorks()
// {
// fingerprinter.setMaximumPathDepth(8);
// BitSet query = fingerprinter.getFingerprint(query());
//
// Set<String> queryPaths = new HashSet(fingerprinter.paths());
//
// System.out.println("query");
// System.out.println(query);
// System.out.println("target");
// BitSet target = fingerprinter.getFingerprint(target());
// System.out.println(target);
//
// Set<String> targetPaths = new HashSet(fingerprinter.paths());
//
// for (String path : queryPaths)
// {
// if (!targetPaths.contains(path))
// {
// System.out.println("missing; " + path);
// }
// }
//
// for (int i = 0; i < query.size(); i++)
// {
// if (query.get(i) == true && !target.get(i) == true)
// {
// System.out.println("missing: " + i);
// }
// }
// }

private Molecule target()
public void testItDoesntMatchCyclooctaneToOctane()
{
String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 10 11 0 0 0 0 0 0 0 0 0 V2000\n 1.0607 2.5607 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.0607 -1.0607 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.5095 -0.6724 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 -0.4635 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n -3.8083 0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 1.9635 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 1.5000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2 1 2 0 0 0 0\n 3 2 1 0 0 0 0\n 4 3 1 0 0 0 0\n 5 4 2 0 0 0 0\n 6 3 1 0 0 0 0\n 7 6 1 0 0 0 0\n 8 7 1 0 0 0 0\n 9 8 1 0 0 0 0\n 10 9 1 0 0 0 0\n 10 2 1 0 0 0 0\n 10 6 1 0 0 0 0\nM END";
// String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 12 13 0 0 0 0 0 0 0 0 0 V2000\n 1.0607 2.5607 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.0607 -1.0607 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.5095 -0.6724 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 -0.4635 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n -3.8083 0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 1.7537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 -0.2537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 1.9635 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 1.5000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2 1 2 0 0 0 0\n 3 2 1 0 0 0 0\n 4 3 1 0 0 0 0\n 5 4 2 0 0 0 0\n 6 3 1 0 0 0 0\n 7 6 1 0 0 0 0\n 8 7 1 0 0 0 0\n 9 8 1 0 0 0 0\n 10 8 1 0 0 0 0\n 11 8 1 0 0 0 0\n 12 11 1 0 0 0 0\n 12 2 1 0 0 0 0\n 12 6 1 0 0 0 0\nM END";
// String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 19 21 0 0 0 0 0 0 0 0 0 V2000\n 1.0607 2.5607 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.0607 -1.0607 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.5095 -0.6724 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.5702 -1.7331 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 4.9860 -1.2377 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 6.2561 -2.0357 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 6.4241 -3.5263 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 5.3634 -4.5869 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.8728 -4.4190 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.0748 -3.1489 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 -0.4635 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n -3.8083 0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 1.7537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 -0.2537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 1.9635 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 1.5000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2 1 2 0 0 0 0\n 3 2 1 0 0 0 0\n 4 3 1 0 0 0 0\n 5 4 2 0 0 0 0\n 6 5 1 0 0 0 0\n 7 6 1 0 0 0 0\n 8 7 1 0 0 0 0\n 9 8 1 0 0 0 0\n 10 9 1 0 0 0 0\n 11 10 1 0 0 0 0\n 12 11 1 0 0 0 0\n 12 6 1 0 0 0 0\n 13 3 1 0 0 0 0\n 14 13 1 0 0 0 0\n 15 14 1 0 0 0 0\n 16 15 1 0 0 0 0\n 17 15 1 0 0 0 0\n 18 15 1 0 0 0 0\n 19 18 1 0 0 0 0\n 19 2 1 0 0 0 0\n 19 13 1 0 0 0 0\nM END";
// String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 30 32 0 0 0 0 0 0 0 0 0 V2000\n 1.0607 2.5607 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.0607 -1.0607 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.5095 -0.6724 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.5702 -1.7331 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 4.9860 -1.2377 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 6.2561 -2.0357 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 6.4241 -3.5263 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 5.3634 -4.5869 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.8728 -4.4190 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 3.0748 -3.1489 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 -0.4635 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n -3.8083 0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 1.7537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -4.9230 -0.2537 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.9266 1.9635 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -3.3901 3.3901 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.3864 4.5048 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n -4.8573 3.7020 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n -5.3209 5.1286 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -6.7881 5.4404 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n -7.2516 6.8670 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -6.2479 7.9817 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n -8.7188 7.1789 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -9.1824 8.6055 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -10.2042 6.9701 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -8.7712 5.6798 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.5000 1.5000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2 1 2 0 0 0 0\n 3 2 1 0 0 0 0\n 4 3 1 0 0 0 0\n 5 4 2 0 0 0 0\n 6 5 1 0 0 0 0\n 7 6 1 0 0 0 0\n 8 7 1 0 0 0 0\n 9 8 1 0 0 0 0\n 10 9 1 0 0 0 0\n 11 10 1 0 0 0 0\n 12 11 1 0 0 0 0\n 12 6 1 0 0 0 0\n 13 3 1 0 0 0 0\n 14 13 1 0 0 0 0\n 15 14 1 0 0 0 0\n 16 15 1 0 0 0 0\n 17 15 1 0 0 0 0\n 18 15 1 0 0 0 0\n 19 18 1 0 0 0 0\n 20 19 2 0 0 0 0\n 21 19 1 0 0 0 0\n 22 21 1 0 0 0 0\n 23 22 1 0 0 0 0\n 24 23 1 0 0 0 0\n 25 24 2 0 0 0 0\n 26 24 1 0 0 0 0\n 27 26 1 0 0 0 0\n 28 26 1 0 0 0 0\n 29 26 1 0 0 0 0\n 30 18 1 0 0 0 0\n 30 2 1 0 0 0 0\n 30 13 1 0 0 0 0\nM END";
BitSet cyclooctane = fingerprinter.getFingerprint(createCyclooctane());
BitSet octane = fingerprinter.getFingerprint(createOctane());

return MoleculeKit.readMolfile(m);
}

private Molecule query()
{
String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 9 10 0 0 0 0 0 0 0 0 0 V2000\n 0.9900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.9900 3.5544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 3.5544 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 5.9443 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 3.3799 5.9443 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5573 2.2229 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n 1.6900 1.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.8226 2.2229 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 2 3 1 0 0 0 0\n 3 4 1 0 0 0 0\n 4 1 1 0 0 0 0\n 1 5 1 0 0 0 0\n 4 6 2 0 0 0 0\n 2 7 1 0 0 0 0\n 7 8 1 0 0 0 0\n 8 9 1 0 0 0 0\n 9 3 1 0 0 0 0\nM END";
// String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 11 12 0 0 0 0 0 0 0 0 0 V2000\n 0.9900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.9900 3.5544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 3.5544 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 5.9443 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 3.3799 5.9443 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5573 2.2229 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n 1.6900 1.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.8226 2.2229 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.6900 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.9374 0.7644 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 2 3 1 0 0 0 0\n 3 4 1 0 0 0 0\n 4 1 1 0 0 0 0\n 1 5 1 0 0 0 0\n 4 6 2 0 0 0 0\n 2 7 1 0 0 0 0\n 7 8 1 0 0 0 0\n 8 9 1 0 0 0 0\n 9 3 1 0 0 0 0\n 8 10 1 0 0 0 0\n 8 11 1 0 0 0 0\nM END";
// String m = "[NO NAME]\n CHEMWRIT 2D\nCreated with ChemWriter - http://metamolecular.com/chemwriter\n 11 12 0 0 0 0 0 0 0 0 0 V2000\n 0.9900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.9900 3.5544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 3.5544 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 2.3900 4.9544 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.0000 5.9443 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n 3.3799 5.9443 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5573 2.2229 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0\n 1.6900 1.4000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.8226 2.2229 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.6900 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.9374 0.7644 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 2 3 1 0 0 0 0\n 3 4 1 0 0 0 0\n 4 1 1 0 0 0 0\n 1 5 1 0 0 0 0\n 4 6 2 0 0 0 0\n 2 7 1 0 0 0 0\n 7 8 1 0 0 0 0\n 8 9 1 0 0 0 0\n 9 3 1 0 0 0 0\n 8 10 1 0 0 0 0\n 8 11 1 0 0 0 0\nM END";

return MoleculeKit.readMolfile(m);
assertFalse(match(cyclooctane, octane));
}

private boolean match(BitSet bitset, BitSet other)
Expand Down
80 changes: 70 additions & 10 deletions src/com/metamolecular/mx/test/PathWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public void testItWritesTwoAtomsSeparatedByADoubleBond()
});

Atom atom1 = mockAtom(".");
when(bond.getMate(atom)).thenReturn(atom1);
when(atom1.getBonds()).thenReturn(new Bond[]
{
bond
Expand All @@ -140,7 +141,6 @@ public void testItWritesTwoAtomsSeparatedByADoubleBond()
sequence.verify(paths).add(".%");
sequence.verify(paths).add(".%.%");
}

public void testItWritesSaturatedAtomForFirstAtomOfDoubleBond()
{
doNew();
Expand All @@ -153,6 +153,7 @@ public void testItWritesSaturatedAtomForFirstAtomOfDoubleBond()

when(bond1.getType()).thenReturn(1);
when(bond2.getType()).thenReturn(2);
when(bond2.getMate(atom2)).thenReturn(atom3);
when(atom1.getBonds()).thenReturn(new Bond[]
{
bond1
Expand All @@ -161,6 +162,10 @@ public void testItWritesSaturatedAtomForFirstAtomOfDoubleBond()
{
bond1, bond2
});
when(atom3.getBonds()).thenReturn(new Bond[]
{
bond2
});

writer.walkStart(atom1);
writer.atomFound(atom1);
Expand All @@ -176,9 +181,11 @@ public void testItWritesSaturatedAtomForFirstAtomOfDoubleBond()
sequence.verify(paths, times(1)).add("12");
sequence.verify(paths, times(1)).add("12%");
sequence.verify(paths, times(1)).add("12%3%");

verify(paths, times(4)).add(any(String.class));
}

public void testItClearsBondPathWhenBranchStarted()
public void testItWritesDoubleBondForRingClosure()
{
doNew();

Expand All @@ -187,32 +194,86 @@ public void testItClearsBondPathWhenBranchStarted()
Atom atom3 = mockAtom("3");
Bond bond1 = mock(Bond.class);
Bond bond2 = mock(Bond.class);
Bond bond3 = mock(Bond.class);

when(bond1.getType()).thenReturn(2);
when(bond1.getType()).thenReturn(1);
when(bond2.getType()).thenReturn(1);
when(bond3.getType()).thenReturn(2);
when(bond3.getMate(atom3)).thenReturn(atom1);
when(atom1.getBonds()).thenReturn(new Bond[]
{
bond1
bond1, bond3
});
when(atom2.getBonds()).thenReturn(new Bond[]
{
bond1, bond2
});
when(atom3.getBonds()).thenReturn(new Bond[]
{
bond2, bond3
});

writer.walkStart(atom1);
writer.atomFound(atom1);
writer.bondFound(bond1);
writer.atomFound(atom2);
writer.branchStart(atom1);
writer.bondFound(bond2);
writer.atomFound(atom3);
writer.branchEnd(atom1);
writer.bondFound(bond3);
writer.ringClosed(bond3);
writer.walkEnd(atom1);

InOrder sequence = inOrder(paths);

sequence.verify(paths, times(1)).add("1%");
sequence.verify(paths, times(1)).add("1%2%");
sequence.verify(paths, times(1)).add("13");
sequence.verify(paths, times(1)).add("1%2");
sequence.verify(paths, times(1)).add("1%23%");
sequence.verify(paths, times(1)).add("1%23%-3");

verify(paths, times(4)).add(any(String.class));
}
public void testItClearsBondPathWhenBranchStarted()
{
doNew();

Atom atom1 = mockAtom("1");
Atom atom2 = mockAtom("2");
Atom atom3 = mockAtom("3");
Bond bond1 = mock(Bond.class);
Bond bond2 = mock(Bond.class);

when(bond1.getType()).thenReturn(1);
when(atom1.getBonds()).thenReturn(new Bond[]
{
bond1
});
when(atom2.getBonds()).thenReturn(new Bond[]
{
bond1, bond2
});
when(atom3.getBonds()).thenReturn(new Bond[]
{
bond2
});

writer.walkStart(atom2);
writer.atomFound(atom2);
writer.bondFound(bond1);
writer.atomFound(atom1);
writer.branchStart(atom2);
writer.bondFound(bond2);
writer.atomFound(atom3);
writer.branchEnd(atom2);
writer.walkEnd(atom2);

InOrder sequence = inOrder(paths);

sequence.verify(paths, times(1)).add("2");
sequence.verify(paths, times(1)).add("21");
sequence.verify(paths, times(1)).add("2");
sequence.verify(paths, times(1)).add("23");

verify(paths, times(4)).add(any(String.class));
}

public void testItBacktracksWhenBranchStarted()
Expand Down Expand Up @@ -371,7 +432,7 @@ public void testItRaisesWhenClosingToEmptyPath()
}
}

public void testItRaisesWhenClosingToNonexistantAtom()
public void testItThrowsWhenClosingToNonexistantAtom()
{
doNew();

Expand Down Expand Up @@ -422,7 +483,6 @@ public void testItRaisesWhenClosingToNonRingAtom()
assertEquals("Atom closes rings with size less than three " + shorty, e.getMessage());
}
}

private void doNew()
{
writer = new PathWriter(paths);
Expand Down
Loading

0 comments on commit 2aa0e27

Please sign in to comment.