Skip to content

Commit

Permalink
CML Bond Conversion Test [patch:3530233]
Browse files Browse the repository at this point in the history
- Added tests for correct wedge/hatch bond conversion
- Added ConvertorTest to libiocml test suite

Change-Id: Ia77be2d00267159ebb24ca3e43d3340914258e15
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Jun 14, 2012
1 parent b4e480c commit 63f0aeb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/test/org/openscience/cdk/libio/cml/ConvertorTest.java
Expand Up @@ -25,13 +25,21 @@
*/
package org.openscience.cdk.libio.cml;

import nu.xom.Document;
import nu.xom.Serializer;
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.Atom;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.libio.md.MDMolecule;
import org.xmlcml.cml.element.CMLAtom;
import org.xmlcml.cml.element.CMLBond;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @cdk.module test-libiocml
Expand Down Expand Up @@ -62,4 +70,61 @@ public class ConvertorTest extends CDKTestCase {
Assert.assertEquals(cmlatom.getHydrogenCount(),0);
}


@Test
public void testCdkBondToCMLBond_Wedge() throws IOException {


IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IBond bond = builder.newInstance(IBond.class);
bond.setOrder(IBond.Order.SINGLE);
bond.setStereo(IBond.Stereo.UP);

Convertor convertor = new Convertor(true, null);
CMLBond cmlBond = convertor.cdkBondToCMLBond(bond);

ByteArrayOutputStream out = new ByteArrayOutputStream();

Serializer serializer = new Serializer(out, "UTF-8");

serializer.write(new Document(cmlBond));

out.close();

String expected = "<bondStereo dictRef=\"cml:W\">W</bondStereo>";
String actual = new String(out.toByteArray());

Assert.assertTrue(actual.contains(expected));

}

@Test
public void testCdkBondToCMLBond_Hatch() throws IOException {


IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IBond bond = builder.newInstance(IBond.class);
bond.setOrder(IBond.Order.SINGLE);
bond.setStereo(IBond.Stereo.DOWN);

Convertor convertor = new Convertor(true, null);
CMLBond cmlBond = convertor.cdkBondToCMLBond(bond);

ByteArrayOutputStream out = new ByteArrayOutputStream();

Serializer serializer = new Serializer(out, "UTF-8");

serializer.write(new Document(cmlBond));

out.close();

String expected = "<bondStereo dictRef=\"cml:H\">H</bondStereo>";
String actual = new String(out.toByteArray());

Assert.assertTrue(actual.contains(expected));


}


}
Expand Up @@ -26,6 +26,7 @@
import org.openscience.cdk.io.cml.CML2Test;
import org.openscience.cdk.io.cml.CML2WriterTest;
import org.openscience.cdk.io.cml.CMLRoundTripTest;
import org.openscience.cdk.libio.cml.ConvertorTest;

/**
* TestSuite that runs all the unit tests for the CDK module libiocml.
Expand All @@ -36,6 +37,7 @@
@SuiteClasses(value={
CML2Test.class,
CML2WriterTest.class,
CMLRoundTripTest.class
CMLRoundTripTest.class,
ConvertorTest.class
})
public class MlibiocmlTests {}

0 comments on commit 63f0aeb

Please sign in to comment.