From: <eg...@us...> - 2007-05-01 12:48:32
|
Revision: 8283 http://svn.sourceforge.net/cdk/?rev=8283&view=rev Author: egonw Date: 2007-05-01 05:48:26 -0700 (Tue, 01 May 2007) Log Message: ----------- More unit like tests Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/test/atomtype/MM2AtomTypeMatcherTest.java trunk/cdk/src/org/openscience/cdk/test/atomtype/MMFF94AtomTypeMatcherTest.java Modified: trunk/cdk/src/org/openscience/cdk/test/atomtype/MM2AtomTypeMatcherTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/atomtype/MM2AtomTypeMatcherTest.java 2007-05-01 10:47:34 UTC (rev 8282) +++ trunk/cdk/src/org/openscience/cdk/test/atomtype/MM2AtomTypeMatcherTest.java 2007-05-01 12:48:26 UTC (rev 8283) @@ -25,21 +25,21 @@ package org.openscience.cdk.test.atomtype; -import java.io.BufferedReader; -//import java.io.FileReader; -import java.io.InputStreamReader; import java.io.InputStream; import junit.framework.Test; import junit.framework.TestSuite; + +import org.openscience.cdk.atomtype.MM2AtomTypeMatcher; +import org.openscience.cdk.interfaces.IAtomType; +import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.io.IChemObjectReader; +import org.openscience.cdk.io.MDLV2000Reader; +import org.openscience.cdk.nonotify.NNMolecule; import org.openscience.cdk.test.CDKTestCase; -import org.openscience.cdk.io.MDLReader; -import org.openscience.cdk.interfaces.IAtomType; -import org.openscience.cdk.atomtype.MM2AtomTypeMatcher; -import org.openscience.cdk.Molecule; -import org.openscience.cdk.tools.manipulator.*; import org.openscience.cdk.tools.AtomTypeTools; import org.openscience.cdk.tools.LoggingTool; +import org.openscience.cdk.tools.manipulator.AtomTypeManipulator; /** * Checks the functionality of the AtomType-MMFF94AtomTypeMatcher. @@ -52,12 +52,35 @@ private LoggingTool logger; + private static IMolecule testMolecule = null; + public MM2AtomTypeMatcherTest(String name) { super(name); } - public void setUp() { + public void setUp() throws Exception { logger = new LoggingTool(this); + + if (testMolecule == null) { + // read the test file and percieve atom types + AtomTypeTools att=new AtomTypeTools(); + MM2AtomTypeMatcher atm= new MM2AtomTypeMatcher(); + logger.debug("**** reading MOL file ******"); + InputStream ins = this.getClass().getClassLoader().getResourceAsStream("data/mdl/mmff94AtomTypeTest_molecule.mol"); + IChemObjectReader mdl = new MDLV2000Reader(ins); + testMolecule=(IMolecule)mdl.read(new NNMolecule()); + assertTrue(testMolecule.getAtomCount() > 0); + logger.debug("Molecule load:"+testMolecule.getAtomCount()); + att.assignAtomTypePropertiesToAtom(testMolecule); + for (int i=0;i<testMolecule.getAtomCount();i++){ + logger.debug("atomNr:"+i); + IAtomType matched = null; + matched = atm.findMatchingAtomType(testMolecule, testMolecule.getAtom(i)); + logger.debug("Found AtomType: ", matched); + assertNotNull(matched); + AtomTypeManipulator.configure(testMolecule.getAtom(i), matched); + } + } } public static Test suite() { @@ -70,40 +93,33 @@ } public void testFindMatchingAtomType_IAtomContainer_IAtom() throws Exception { - if (!this.runSlowTests()) fail("Slow tests turned of"); - - logger.debug("**** START MM2 ATOMTYPE TEST ******"); - AtomTypeTools att=new AtomTypeTools(); - Molecule mol=null; - MM2AtomTypeMatcher atm= new MM2AtomTypeMatcher(); - BufferedReader fin =null; - InputStream ins=null; - logger.debug("**** reading MOL file ******"); - ins = this.getClass().getClassLoader().getResourceAsStream("data/mdl/mmff94AtomTypeTest_molecule.mol"); - fin = new BufferedReader(new InputStreamReader(ins)); - MDLReader mdl=new MDLReader(fin); - mol=(Molecule)mdl.read(new Molecule()); - assertTrue(mol.getAtomCount() > 0); - logger.debug("Molecule load:"+mol.getAtomCount()); - att.assignAtomTypePropertiesToAtom(mol); - for (int i=0;i<mol.getAtomCount();i++){ - logger.debug("atomNr:"+i); - IAtomType matched = null; - matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); - logger.debug("Found AtomType: ", matched); - assertNotNull(matched); - AtomTypeManipulator.configure(mol.getAtom(i), matched); - } - - logger.debug("MM2 Atom 0:"+mol.getAtom(0).getAtomTypeName()); - - assertEquals("Sthi",mol.getAtom(0).getAtomTypeName()); - assertEquals("Csp2",mol.getAtom(7).getAtomTypeName()); - assertEquals("Csp",mol.getAtom(51).getAtomTypeName()); - assertEquals("N=C",mol.getAtom(148).getAtomTypeName()); - assertEquals("Oar",mol.getAtom(198).getAtomTypeName()); - assertEquals("N2OX",mol.getAtom(233).getAtomTypeName()); - assertEquals("Nsp2",mol.getAtom(256).getAtomTypeName()); - logger.debug("**** END OF ATOMTYPE TEST ******"); + for (int i=0;i<testMolecule.getAtomCount();i++) { + assertNotNull(testMolecule.getAtom(i).getAtomTypeName()); + assertTrue(testMolecule.getAtom(i).getAtomTypeName().length() > 0); + } } + + // FIXME: Below should be tests for *all* atom types in the MM2 atom type specificiation + + public void testSthi() { + assertEquals("Sthi",testMolecule.getAtom(0).getAtomTypeName()); + } + public void testCsp2() { + assertEquals("Csp2",testMolecule.getAtom(7).getAtomTypeName()); + } + public void testCsp() { + assertEquals("Csp",testMolecule.getAtom(51).getAtomTypeName()); + } + public void testNdbC() { + assertEquals("N=C",testMolecule.getAtom(148).getAtomTypeName()); + } + public void testOar() { + assertEquals("Oar",testMolecule.getAtom(198).getAtomTypeName()); + } + public void testN2OX() { + assertEquals("N2OX",testMolecule.getAtom(233).getAtomTypeName()); + } + public void testNsp2() { + assertEquals("Nsp2",testMolecule.getAtom(256).getAtomTypeName()); + } } Modified: trunk/cdk/src/org/openscience/cdk/test/atomtype/MMFF94AtomTypeMatcherTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/atomtype/MMFF94AtomTypeMatcherTest.java 2007-05-01 10:47:34 UTC (rev 8282) +++ trunk/cdk/src/org/openscience/cdk/test/atomtype/MMFF94AtomTypeMatcherTest.java 2007-05-01 12:48:26 UTC (rev 8283) @@ -25,7 +25,6 @@ package org.openscience.cdk.test.atomtype; -import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -44,6 +43,7 @@ import org.openscience.cdk.interfaces.IChemObjectBuilder; import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.io.MDLReader; +import org.openscience.cdk.nonotify.NNMolecule; import org.openscience.cdk.test.CDKTestCase; import org.openscience.cdk.tools.AtomTypeTools; import org.openscience.cdk.tools.HydrogenAdder; @@ -62,13 +62,37 @@ private LoggingTool logger; private final IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); private HydrogenAdder haad=new HydrogenAdder(); + + private static IMolecule testMolecule = null; + public MMFF94AtomTypeMatcherTest(String name) { super(name); } - public void setUp() { + public void setUp() throws Exception { logger = new LoggingTool(this); } + + public void setUpTestMolecule() throws Exception { + if (testMolecule == null) { + //logger.debug("**** START ATOMTYPE TEST ******"); + AtomTypeTools att=new AtomTypeTools(); + MMFF94AtomTypeMatcher atm= new MMFF94AtomTypeMatcher(); + InputStream ins=this.getClass().getClassLoader().getResourceAsStream("data/mdl/mmff94AtomTypeTest_molecule.mol"); + MDLReader mdl=new MDLReader(new InputStreamReader(ins)); + testMolecule=(Molecule)mdl.read(new NNMolecule()); + + att.assignAtomTypePropertiesToAtom(testMolecule); + for (int i=0;i<testMolecule.getAtomCount();i++){ + logger.debug("atomNr:" + testMolecule.getAtom(i).toString()); + IAtomType matched = atm.findMatchingAtomType(testMolecule, testMolecule.getAtom(i)); + assertNotNull(matched); + AtomTypeManipulator.configure(testMolecule.getAtom(i), matched); + } + + logger.debug("MMFF94 Atom 0:"+testMolecule.getAtom(0).getAtomTypeName()); + } + } public static Test suite() { return new TestSuite(MMFF94AtomTypeMatcherTest.class); @@ -81,42 +105,46 @@ } public void testFindMatchingAtomType_IAtomContainer_IAtom() throws ClassNotFoundException, CDKException, java.lang.Exception { - if (!this.runSlowTests()) fail("Slow tests turned of"); - - //logger.debug("**** START ATOMTYPE TEST ******"); - AtomTypeTools att=new AtomTypeTools(); - //SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); - Molecule mol=null; - //HydrogenAdder hAdder = new HydrogenAdder(); - MMFF94AtomTypeMatcher atm= new MMFF94AtomTypeMatcher(); - BufferedReader fin =null; - InputStream ins=this.getClass().getClassLoader().getResourceAsStream("data/mdl/mmff94AtomTypeTest_molecule.mol"); - fin = new BufferedReader(new InputStreamReader(ins)); - //fin=new BufferedReader(new FileReader("data/mmff94AtomTypeTest_molecule.mol")); - MDLReader mdl=new MDLReader(fin); - mol=(Molecule)mdl.read(new Molecule()); - - att.assignAtomTypePropertiesToAtom(mol); - for (int i=0;i<mol.getAtomCount();i++){ - logger.debug("atomNr:" + mol.getAtom(i).toString()); - IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); - assertNotNull(matched); - AtomTypeManipulator.configure(mol.getAtom(i), matched); - } - - logger.debug("MMFF94 Atom 0:"+mol.getAtom(0).getAtomTypeName()); - //logger.debug("Atom 0:"+mol.getAtomAt(256).getAtomTypeName()); - - assertEquals("Sthi",mol.getAtom(0).getAtomTypeName()); - assertEquals("Csp2",mol.getAtom(7).getAtomTypeName()); - assertEquals("Csp",mol.getAtom(51).getAtomTypeName()); - assertEquals("N=O",mol.getAtom(148).getAtomTypeName()); - assertEquals("Oar",mol.getAtom(198).getAtomTypeName()); - assertEquals("N2OX",mol.getAtom(233).getAtomTypeName()); - assertEquals("NAZT",mol.getAtom(256).getAtomTypeName()); - //logger.debug("**** END OF ATOMTYPE TEST ******"); + setUpTestMolecule(); + for (int i=0;i<testMolecule.getAtomCount();i++) { + assertNotNull(testMolecule.getAtom(i).getAtomTypeName()); + assertTrue(testMolecule.getAtom(i).getAtomTypeName().length() > 0); + } } + // FIXME: Below should be tests for *all* atom types in the MM2 atom type specificiation + + public void testSthi() throws Exception { + setUpTestMolecule(); + assertEquals("Sthi",testMolecule.getAtom(0).getAtomTypeName()); + } + public void testCsp2() throws Exception { + setUpTestMolecule(); + assertEquals("Csp2",testMolecule.getAtom(7).getAtomTypeName()); + } + public void testCsp() throws Exception { + setUpTestMolecule(); + assertEquals("Csp",testMolecule.getAtom(51).getAtomTypeName()); + } + public void testNdbO() throws Exception { + setUpTestMolecule(); + assertEquals("N=O",testMolecule.getAtom(148).getAtomTypeName()); + } + public void testOar() throws Exception { + setUpTestMolecule(); + assertEquals("Oar",testMolecule.getAtom(198).getAtomTypeName()); + } + public void testN2OX() throws Exception { + setUpTestMolecule(); + assertEquals("N2OX",testMolecule.getAtom(233).getAtomTypeName()); + } + public void testNAZT() throws Exception { + setUpTestMolecule(); + assertEquals("NAZT",testMolecule.getAtom(256).getAtomTypeName()); + } + + // Other tests + public void testFindMatchingAtomType_IAtomContainer_IAtom_Methanol() throws ClassNotFoundException, CDKException, java.lang.Exception { // logger.debug("**** START ATOMTYPE Methanol TEST ******"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |