Skip to content

Commit

Permalink
Moved all tests with smiles from cdk-test-io to cdk-test-smiles
Browse files Browse the repository at this point in the history
Conflicts:
	src/META-INF/test-io.devellibdepends

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Jul 31, 2013
1 parent 5cc687d commit 1479cad
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 36 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,15 @@
list="test"/>
<foreach target="compile-module" param="module" trim="true"
parallel="${parallel}" maxthreads="${threadCount}"
list="test-interfaces,test-libiocml,test-qsar,test-io,test-core,
list="test-interfaces,test-libiocml,test-qsar,test-data,test-io,test-core,
test-valencycheck,test-smarts,test-standard,test-reaction,
test-pcore,test-sdg,test-forcefield,test-fingerprint,
test-ionpot,test-qm,test-isomorphism,test-libiomd,test-dict,
test-diff,test-charges,test-inchi,
test-render,test-ioformats,test-log4j,test-cip"/>
<foreach target="compile-module" param="module" trim="true"
parallel="${parallel}" maxthreads="${threadCount}"
list="test-data,test-formula,test-qsaratomic,test-qsarbond,
list="test-formula,test-qsaratomic,test-qsarbond,
test-pdb,test-smiles,test-extra,test-fragment,test-atomtype,
test-structgen,test-iordf,test-silent"/>
<foreach target="compile-module" param="module" trim="true"
Expand Down
1 change: 1 addition & 0 deletions src/META-INF/test-io.cdkdepends
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cdk-interfaces.jar
cdk-core.jar
cdk-standard.jar
cdk-data.jar
cdk-test-data.jar
cdk-datadebug.jar
cdk-silent.jar
cdk-io.jar
Expand Down
1 change: 1 addition & 0 deletions src/META-INF/test-io.devellibdepends
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
junit-4.11.jar
hamcrest-core-1.3.jar
mockito-all-1.9.5.jar
groovy.jar
asm-3.2.jar
antlr.jar
1 change: 1 addition & 0 deletions src/META-INF/test-smiles.cdkdepends
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cdk-annotation.jar
cdk-interfaces.jar
cdk-atomtype.jar
cdk-core.jar
cdk-standard.jar
cdk-data.jar
Expand Down
35 changes: 19 additions & 16 deletions src/test/org/openscience/cdk/io/MDLV2000WriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -45,6 +44,7 @@
import org.openscience.cdk.ChemModel;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.PseudoAtom;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
Expand All @@ -55,12 +55,11 @@
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.MoleculeFactory;
import org.openscience.cdk.templates.TestMoleculeFactory;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.openscience.cdk.CDKConstants.ISAROMATIC;


/**
Expand Down Expand Up @@ -121,7 +120,7 @@ public class MDLV2000WriterTest extends ChemObjectIOTest {

@Test public void testWriteValence() throws Exception {
StringWriter writer = new StringWriter();
IAtomContainer molecule = MoleculeFactory.makeAlphaPinene();
IAtomContainer molecule = TestMoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setValency(1);
molecule.getAtom(1).setValency(0);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
Expand All @@ -138,7 +137,7 @@ public class MDLV2000WriterTest extends ChemObjectIOTest {

@Test public void testWriteAtomAtomMapping() throws Exception {
StringWriter writer = new StringWriter();
IAtomContainer molecule = MoleculeFactory.makeAlphaPinene();
IAtomContainer molecule = TestMoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING,1);
molecule.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING,15);
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
Expand All @@ -153,7 +152,7 @@ public class MDLV2000WriterTest extends ChemObjectIOTest {
*/
@Test public void testWriteStringAtomAtomMapping() throws Exception {
StringWriter writer = new StringWriter();
IAtomContainer molecule = MoleculeFactory.makeAlphaPinene();
IAtomContainer molecule = TestMoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING,"1");
molecule.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING,"15");
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
Expand All @@ -168,7 +167,7 @@ public class MDLV2000WriterTest extends ChemObjectIOTest {
*/
@Test public void testWriteInvalidAtomAtomMapping() throws Exception {
StringWriter writer = new StringWriter();
IAtomContainer molecule = MoleculeFactory.makeAlphaPinene();
IAtomContainer molecule = TestMoleculeFactory.makeAlphaPinene();
molecule.getAtom(0).setProperty(CDKConstants.ATOM_ATOM_MAPPING,"1a");
molecule.getAtom(1).setProperty(CDKConstants.ATOM_ATOM_MAPPING,"15");
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
Expand Down Expand Up @@ -268,7 +267,7 @@ public class MDLV2000WriterTest extends ChemObjectIOTest {
}

@Test public void testUndefinedStereo() throws Exception {
IAtomContainer mol = MoleculeFactory.makeAlphaPinene();
IAtomContainer mol = TestMoleculeFactory.makeAlphaPinene();
mol.getBond(0).setStereo(IBond.Stereo.UP_OR_DOWN);
mol.getBond(1).setStereo(IBond.Stereo.E_OR_Z);
StringWriter writer = new StringWriter();
Expand Down Expand Up @@ -296,9 +295,9 @@ public void testUnsupportedBondOrder() throws Exception {
}

@Test public void testTwoFragmentsWithTitle() throws CDKException{
IAtomContainer mol1 = MoleculeFactory.makeAlphaPinene();
IAtomContainer mol1 = TestMoleculeFactory.makeAlphaPinene();
mol1.setProperty(CDKConstants.TITLE,"title1");
IAtomContainer mol2 = MoleculeFactory.makeAlphaPinene();
IAtomContainer mol2 = TestMoleculeFactory.makeAlphaPinene();
mol2.setProperty(CDKConstants.TITLE,"title2");
IChemModel model = mol1.getBuilder().newInstance(IChemModel.class);
model.setMoleculeSet(mol1.getBuilder().newInstance(IAtomContainerSet.class));
Expand Down Expand Up @@ -374,15 +373,19 @@ public void testUnsupportedBondOrder() throws Exception {
* @throws Exception
*/
@Test public void testAromaticBondType4() throws Exception {
SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
String smiles = "c1ccccc1";
IAtomContainer benzene = sp.parseSmiles(smiles);

IAtomContainer benzene = TestMoleculeFactory.makeBenzene();
for(IAtom atom : benzene.atoms()) {
atom.setFlag(ISAROMATIC, true);
}
for(IBond bond : benzene.bonds()) {
bond.setFlag(ISAROMATIC, true);
}

StringWriter writer = new StringWriter();
MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);
mdlWriter.write(benzene);
Assert.assertTrue(writer.toString().indexOf("2 1 1 0 0 0 0") != -1);
Assert.assertTrue(writer.toString().indexOf("1 2 1 0 0 0 0") != -1);


writer = new StringWriter();
Expand All @@ -393,7 +396,7 @@ public void testUnsupportedBondOrder() throws Exception {
mdlWriter.addChemObjectIOListener(listener);
mdlWriter.customizeJob();
mdlWriter.write(benzene);
Assert.assertTrue(writer.toString().indexOf("2 1 4 0 0 0 0") != -1);
Assert.assertTrue(writer.toString().indexOf("1 2 4 0 0 0 0") != -1);
}

@Test
Expand Down
20 changes: 10 additions & 10 deletions src/test/org/openscience/cdk/io/Mol2WriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.DefaultChemObjectBuilder;
Expand All @@ -35,7 +36,6 @@
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

Expand All @@ -44,11 +44,14 @@
import java.io.StringWriter;
import java.util.List;

import static org.mockito.Mockito.mock;

/**
* TestCase for the writer MOL2 writer.
*
* @cdk.module test-io
* @see Mol2Writer
* @see SMILES2Mol2WriterTest
*/
public class Mol2WriterTest extends ChemObjectIOTest {

Expand All @@ -71,10 +74,9 @@ public void testAccepts() throws Exception {
* @throws IOException
* @cdk.bug 2675188
*/
@Test
@Ignore("moved to SMILES2Mol2WriterTest")
public void testWriter1() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("C([H])([H])([H])([H])");
IAtomContainer molecule = mock(IAtomContainer.class);

StringWriter swriter = new StringWriter();
Mol2Writer writer = new Mol2Writer(swriter);
Expand All @@ -84,10 +86,9 @@ public void testWriter1() throws Exception {
Assert.assertTrue(swriter.getBuffer().toString().indexOf("1 2 1 1") > 0);
}

@Test
@Ignore("moved to SMILES2Mol2WriterTest")
public void testWriter2() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("c1ccccc1C=O");
IAtomContainer molecule = mock(IAtomContainer.class);
CDKHueckelAromaticityDetector.detectAromaticity(molecule);

StringWriter swriter = new StringWriter();
Expand All @@ -104,10 +105,9 @@ public void testWriter2() throws Exception {
Assert.assertTrue(swriter.getBuffer().toString().indexOf("8 8 7 2") > 0);
}

@Test
@Ignore("moved to SMILES2Mol2WriterTest")
public void testWriterForAmide() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("CC(=O)NC");
IAtomContainer molecule = mock(IAtomContainer.class);
CDKHueckelAromaticityDetector.detectAromaticity(molecule);

StringWriter swriter = new StringWriter();
Expand Down
16 changes: 12 additions & 4 deletions src/test/org/openscience/cdk/io/SDFWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.AtomContainerSet;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.smiles.InvPair;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.templates.TestMoleculeFactory;

import static org.openscience.cdk.CDKConstants.ISAROMATIC;

/**
* TestCase for the writer MDL SD file writer.
Expand Down Expand Up @@ -193,9 +197,13 @@ public class SDFWriterTest extends ChemObjectWriterTest {
*/
@Test
public void testIOPropPropagation() throws Exception {
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
IAtomContainer mol = sp.parseSmiles("c1ccccc1CC");
CDKHueckelAromaticityDetector.detectAromaticity(mol);
IAtomContainer mol = TestMoleculeFactory.makeBenzene();
for(IAtom atom : mol.atoms()) {
atom.setFlag(ISAROMATIC, true);
}
for(IBond bond : mol.bonds()) {
bond.setFlag(ISAROMATIC, true);
}

StringWriter strWriter = new StringWriter();
SDFWriter writer = new SDFWriter(strWriter);
Expand Down
112 changes: 112 additions & 0 deletions src/test/org/openscience/cdk/io/SMILES2Mol2WriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2013. John May <jwmay@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U
*/
package org.openscience.cdk.io;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

import java.io.InputStream;
import java.io.StringWriter;
import java.util.List;

/**
* TestCase for the writer MOL2 writer from smiles.
*
* @cdk.module test-smiles
* @see org.openscience.cdk.io.Mol2Writer
*/
public class SMILES2Mol2WriterTest {

private static IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();

/**
* @throws org.openscience.cdk.exception.CDKException
* @throws java.io.IOException
* @cdk.bug 2675188
*/
@Test
public void testWriter1() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("C([H])([H])([H])([H])");

StringWriter swriter = new StringWriter();
Mol2Writer writer = new Mol2Writer(swriter);
writer.write(molecule);
writer.close();
Assert.assertTrue(swriter.getBuffer().toString().indexOf("1 C1 0.000 0.000 0.000 C.3") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("1 2 1 1") > 0);
}

@Test
public void testWriter2() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("c1ccccc1C=O");
CDKHueckelAromaticityDetector.detectAromaticity(molecule);

StringWriter swriter = new StringWriter();
Mol2Writer writer = new Mol2Writer(swriter);
writer.write(molecule);
writer.close();

Assert.assertTrue("Aromatic atom not properly reported",
swriter.getBuffer().toString().indexOf("1 C1 0.000 0.000 0.000 C.ar") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("8 O8 0.000 0.000 0.000 O.2") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("7 C7 0.000 0.000 0.000 C.2") > 0);
Assert.assertTrue("Aromatic bond not properly reported",
swriter.getBuffer().toString().indexOf("1 2 1 ar") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("8 8 7 2") > 0);
}

@Test
public void testWriterForAmide() throws Exception {
SmilesParser sp = new SmilesParser(builder);
IAtomContainer molecule = sp.parseSmiles("CC(=O)NC");
CDKHueckelAromaticityDetector.detectAromaticity(molecule);

StringWriter swriter = new StringWriter();
Mol2Writer writer = new Mol2Writer(swriter);
writer.write(molecule);
writer.close();

Assert.assertTrue(swriter.getBuffer().toString().indexOf("1 C1 0.000 0.000 0.000 C.3") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("3 O3 0.000 0.000 0.000 O.") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("4 N4 0.000 0.000 0.000 N.a") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("1 2 1 1") > 0);
Assert.assertTrue("Amide bond not properly reported",
swriter.getBuffer().toString().indexOf("3 4 2 am") > 0);
Assert.assertTrue(swriter.getBuffer().toString().indexOf("4 5 4 1") > 0);
}
}
2 changes: 1 addition & 1 deletion src/test/org/openscience/cdk/io/SMILESWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* TestCase for the writer for SMILES files.
*
* @cdk.module test-io
* @cdk.module test-smiles
*
* @see org.openscience.cdk.io.SMILESWriter
*/
Expand Down

0 comments on commit 1479cad

Please sign in to comment.