From: gilleain t. <gil...@gm...> - 2009-01-30 18:23:37
|
I just noticed Rajarshi's changes to the PolymerTest.testPolymerClone method, and realized that this patch of mine may have been missed. The changes are almost the same, but go further in testing that the Monomers are not shared, and that the atoms they contain are not shared. gilleain ---------- Forwarded message ---------- From: gilleain torrance <gil...@gm...> Date: Sun, Jan 4, 2009 at 12:09 AM Subject: possible patch to the 1.2 branch for the Polymer stuff To: Egon Willighagen <ego...@gm...> Hi Egon, I know you've been improving the tests in cdk 1.2, and I was looking at the Polymer.clone method. I changed the unit test a little (I'm trying to get used to them :) and I think that the clone still wasn't working right. I hate cloning. Anyway, this patch solves the problem, and it also seems to be doing things more logically. Sadly it doesn't solve the problem of bug #2454890... gilleain ### Eclipse Workspace Patch 1.0 #P cdk_1.2 Index: src/main/org/openscience/cdk/Polymer.java =================================================================== --- src/main/org/openscience/cdk/Polymer.java (revision 13795) +++ src/main/org/openscience/cdk/Polymer.java (working copy) @@ -145,12 +145,12 @@ Polymer clone = (Polymer)super.clone(); clone.removeAllElements(); clone.monomers = new Hashtable<String, IMonomer>(); - for (Iterator<String> iter = clone.getMonomerNames().iterator(); iter.hasNext();) { - Monomer monomerClone = (Monomer)(clone.getMonomer(iter.next().toString()).clone()); - Iterator<IAtom> atoms = monomerClone.atoms().iterator(); - while (atoms.hasNext()) { - clone.addAtom(atoms.next(), monomerClone); - } + for (String monomerName : monomers.keySet()) { + IMonomer monomer = this.getMonomer(monomerName); + IMonomer monomerClone = (IMonomer)(monomer.clone()); + for (IAtom atom : monomer.atoms()) { + clone.addAtom((IAtom)atom.clone(), monomerClone); + } } return clone; } Index: src/test/org/openscience/cdk/PolymerTest.java =================================================================== --- src/test/org/openscience/cdk/PolymerTest.java (revision 13795) +++ src/test/org/openscience/cdk/PolymerTest.java (working copy) @@ -30,6 +30,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IChemObject; import org.openscience.cdk.interfaces.IPolymer; import org.openscience.cdk.interfaces.AbstractPolymerTest; @@ -77,5 +78,14 @@ oPolymer.addAtom(new Atom("C"), monomer); Assert.assertEquals(0, clone.getMonomerCount()); Assert.assertEquals(0, clone.getMonomerNames().size()); + + // alter and reclone to get a polymer with the added monomer + oPolymer.getMonomer("TYR55").getAtom(0).setSymbol("N"); + Polymer newClone = (Polymer)oPolymer.clone(); + IAtom atom = newClone.getAtom(0); + Assert.assertNotNull(oPolymer.getAtom(0)); + Assert.assertNotNull(atom); + String symbol = atom.getSymbol(); + Assert.assertEquals(symbol, "N"); } } |