Skip to content
Permalink
Browse files

added unit test to demonstrate bug and correct bug id's for two recen…

…ts tests

Change-Id: If2c12c6dfaad4c7664b5ec6d439f8ddbec9f2ae9
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Nov 4, 2012
1 parent fefc82d commit 0ea90e8f307844dbea5b3016a6250a22f3d71802
@@ -0,0 +1,33 @@
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<!-- A very simple molecule to test bug 1274
- The bondStereo should use the dictRef attribute when both dictRef and
charContent is available.
- The bond stereo should only be set for this single bond
-->
<molecule molID="m1">
<atomArray>
<atom id="a1" elementType="C"
x2="-1.3200000524520874" y2="-1.815000057220459"/>
<atom id="a2" elementType="N"
x2="0.013679069375948316" y2="-2.585000057220459"/>
<atom id="a3" elementType="C"
x2="-2.6536791742801227" y2="-2.5850000572204594"/>
<atom id="a4" elementType="O"
x2="-1.3200000524520874" y2="-0.27500005722045895"/>
</atomArray>
<bondArray>
<bond atomRefs2="a1 a2" order="1"/>
<bond atomRefs2="a1 a4" order="1">
<!-- this is bad formatting - but we should favour the dictRef
a logging error should shown for this case -->
<bondStereo dictRef="cml:H">W</bondStereo>
</bond>
<bond atomRefs2="a1 a3" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>
@@ -2,9 +2,9 @@
<cml>
<MDocument>
<MChemicalStruct>
<!-- A very molecule to test bug 3553328 and 3557907
- 3553328: Atoms missing explicit atomic number default to 1.
- 3557907: Only support for bond stereo with attribute dictRef
<!-- A very simple molecule to test bug 1245 and 1248
- 1245: Atoms missing explicit atomic number default to 1.
- 1248: Only support for bond stereo with attribute dictRef
-->
<molecule molID="m1">
<atomArray>
@@ -36,6 +36,7 @@
import org.openscience.cdk.tools.periodictable.PeriodicTable;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
@@ -70,7 +71,7 @@ public void testSetReader_Reader() throws Exception {
* Ensure stereoBond content is read if the usual "dictRef" attribute is not
* supplied
*
* @cdk.bug 3557907
* @cdk.bug 1248
*/
@Test
public void testBug3557907() throws FileNotFoundException, CDKException {
@@ -102,7 +103,7 @@ public void testBug3557907() throws FileNotFoundException, CDKException {
/**
* Ensure correct atomic numbers are read and does not default to 1
*
* @cdk.bug 3553328
* @cdk.bug 1245
*/
@Test
public void testBug3553328() throws FileNotFoundException, CDKException {
@@ -126,6 +127,65 @@ public void testBug3553328() throws FileNotFoundException, CDKException {
PeriodicTable.getAtomicNumber(atom.getSymbol()),
atom.getAtomicNumber());
}
}

/**
* Ensures that when multiple stereo is set the dictRef is favoured
* and the charContent is not used. Here is an example of what we expect
* to read.
*
* <pre>{@code
* <bond atomRefs2="a1 a4" order="1">
* <bondStereo dictRef="cml:W"/> <!-- should be W -->
* </bond>
*
* <bond atomRefs2="a1 a4" order="1">
* <bondStereo>W</bondStereo> <!-- should be W -->
* </bond>
*
* <bond atomRefs2="a1 a4" order="1">
* <bondStereo dictRef="cml:W">W</bondStereo> <!-- should be W -->
* </bond>
*
* <bond atomRefs2="a1 a4" order="1">
* <bondStereo dictRef="cml:W">H</bondStereo> <!-- should be W -->
* </bond>
* }</pre>
*
* @cdk.bug 1274
* @see #testBug1248()
*/
@Test
public void testBug1274() throws CDKException, IOException {

InputStream in = getClass().getResourceAsStream("/data/cml/(1R)-1-aminoethan-1-ol-multipleBondStereo.cml");
CMLReader reader = new CMLReader(in);
try {
IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class));


Assert.assertNotNull("ChemFile was null", cfile);

List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cfile);

Assert.assertEquals("expected a single atom container", 1, containers.size());

IAtomContainer container = containers.get(0);

Assert.assertNotNull("null atom container read", container);

// we check here that the charContent is not used and also that more then
// one stereo isn't set
Assert.assertEquals("expected non-stereo bond",
IBond.Stereo.NONE, container.getBond(0).getStereo());
Assert.assertEquals("expected Hatch (Down) Bond",
IBond.Stereo.DOWN, container.getBond(1).getStereo());
Assert.assertEquals("expected non-stereo bond",
IBond.Stereo.NONE, container.getBond(2).getStereo());

} finally {
reader.close();
}
}

}

0 comments on commit 0ea90e8

Please sign in to comment.
You can’t perform that action at this time.