From: <eg...@us...> - 2008-02-11 05:22:39
|
Revision: 10050 http://cdk.svn.sourceforge.net/cdk/?rev=10050&view=rev Author: egonw Date: 2008-02-10 21:22:34 -0800 (Sun, 10 Feb 2008) Log Message: ----------- Test that after assigning atom types, perception is identical as befor those assignments Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/test/atomtype/AbstractAtomTypeTest.java trunk/cdk/src/org/openscience/cdk/test/atomtype/CDKAtomTypeMatcherTest.java Modified: trunk/cdk/src/org/openscience/cdk/test/atomtype/AbstractAtomTypeTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/atomtype/AbstractAtomTypeTest.java 2008-02-10 19:49:04 UTC (rev 10049) +++ trunk/cdk/src/org/openscience/cdk/test/atomtype/AbstractAtomTypeTest.java 2008-02-11 05:22:34 UTC (rev 10050) @@ -24,8 +24,13 @@ import java.util.Map; import org.junit.Assert; +import org.openscience.cdk.atomtype.CDKAtomTypeMatcher; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IAtomType; import org.openscience.cdk.test.NewCDKTestCase; +import org.openscience.cdk.tools.manipulator.AtomTypeManipulator; /** * Helper class that all atom type matcher test classes must implement. @@ -36,11 +41,32 @@ */ abstract public class AbstractAtomTypeTest extends NewCDKTestCase { + public void assertAtomTypes(Map<String, Integer> testedAtomTypes, String[] expectedTypes, IAtomContainer mol) throws CDKException { + Assert.assertEquals( + "The number of expected atom types is unequal to the number of atoms", + expectedTypes.length, mol.getAtomCount() + ); + CDKAtomTypeMatcher atm = CDKAtomTypeMatcher.getInstance(mol.getBuilder()); + for (int i=0; i<expectedTypes.length; i++) { + IAtom testedAtom = mol.getAtom(i); + IAtomType foundType = atm.findMatchingAtomType(mol, testedAtom); + assertAtomType(testedAtomTypes, expectedTypes[i], foundType); + // test for bug #1890702: configure, and then make sure the same atom type is perceived + AtomTypeManipulator.configure(testedAtom, foundType); + IAtomType secondType = atm.findMatchingAtomType(mol, testedAtom); + assertAtomType(testedAtomTypes, + "Incorrect perception *after* assigning atom type properties.", + expectedTypes[i], secondType + ); + } + } + public void assertAtomType(Map<String, Integer> testedAtomTypes, String expectedID, IAtomType foundAtomType) { - addTestedAtomType(testedAtomTypes, expectedID); - - Assert.assertNotNull("No atom type percieved! Expected atom type: " + expectedID, foundAtomType); - Assert.assertEquals(expectedID, foundAtomType.getAtomTypeName()); + this.assertAtomType( + testedAtomTypes, + "No atom type percieved! Expected atom type: " + expectedID, + expectedID, foundAtomType + ); } public void assertAtomType(Map<String, Integer> testedAtomTypes, String error, String expectedID, IAtomType foundAtomType) { Modified: trunk/cdk/src/org/openscience/cdk/test/atomtype/CDKAtomTypeMatcherTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/atomtype/CDKAtomTypeMatcherTest.java 2008-02-10 19:49:04 UTC (rev 10049) +++ trunk/cdk/src/org/openscience/cdk/test/atomtype/CDKAtomTypeMatcherTest.java 2008-02-11 05:22:34 UTC (rev 10050) @@ -108,9 +108,8 @@ mol.addAtom(atom2); mol.addBond(0,1,CDKConstants.BONDORDER_DOUBLE); - CDKAtomTypeMatcher atm = CDKAtomTypeMatcher.getInstance(mol.getBuilder()); - assertAtomType(testedAtomTypes, "C.sp2", atm.findMatchingAtomType(mol, atom)); - assertAtomType(testedAtomTypes, "C.sp2", atm.findMatchingAtomType(mol, atom2)); + String[] expectedTypes = {"C.sp2", "C.sp2"}; + assertAtomTypes(testedAtomTypes, expectedTypes, mol); } @Test public void testGuanineMethyl() throws Exception { @@ -153,17 +152,10 @@ mol.addBond(8,11,CDKConstants.BONDORDER_SINGLE); mol.addBond(8,9,CDKConstants.BONDORDER_SINGLE); - CDKAtomTypeMatcher atm = CDKAtomTypeMatcher.getInstance(mol.getBuilder()); String[] expectedTypes = {"C.sp2", "N.planar3", "C.sp2", "N.sp2", "C.sp3", "C.sp2", "N.sp2", "C.sp2", "C.sp2", "N.planar3", "O.sp2", "N.sp3"}; - for (int i=0; i<expectedTypes.length; i++) { - System.out.println("Tested AT " + (i+1) + ": " + expectedTypes[i]); - assertAtomType(testedAtomTypes, - expectedTypes[i], - atm.findMatchingAtomType(mol, mol.getAtom(i)) - ); - } + assertAtomTypes(testedAtomTypes, expectedTypes, mol); } @Test public void testPropyne() throws Exception { @@ -177,10 +169,8 @@ mol.addBond(0,1,CDKConstants.BONDORDER_TRIPLE); mol.addBond(2,1,CDKConstants.BONDORDER_SINGLE); - CDKAtomTypeMatcher atm = CDKAtomTypeMatcher.getInstance(mol.getBuilder()); - assertAtomType(testedAtomTypes, "C.sp", atm.findMatchingAtomType(mol, atom)); - assertAtomType(testedAtomTypes, "C.sp", atm.findMatchingAtomType(mol, atom2)); - assertAtomType(testedAtomTypes, "C.sp3", atm.findMatchingAtomType(mol, atom3)); + String[] expectedTypes = {"C.sp", "C.sp", "C.sp3"}; + assertAtomTypes(testedAtomTypes, expectedTypes, mol); } @Test public void testFormaldehyde() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |