Navigation Menu

Skip to content

Commit

Permalink
added unit test to demonstrate bug and correct bug id's for two recen…
Browse files Browse the repository at this point in the history
…ts tests

Change-Id: If2c12c6dfaad4c7664b5ec6d439f8ddbec9f2ae9
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Nov 6, 2012
1 parent fefc82d commit 0ea90e8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/test/data/cml/(1R)-1-aminoethan-1-ol-multipleBondStereo.cml
@@ -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>
6 changes: 3 additions & 3 deletions src/test/data/cml/(1R)-1-aminoethan-1-ol.cml
Expand Up @@ -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>
Expand Down
64 changes: 62 additions & 2 deletions src/test/org/openscience/cdk/io/CMLReaderTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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.