Skip to content

Commit

Permalink
Added unit tests for bugs 1270 (removalAllElements should remove ster…
Browse files Browse the repository at this point in the history
…eo elements) and 1273 (double bond stereo chemistry constructor should throw an exception on wrong input). Added @cdk.bug tag for bug 1264 (stereo element cloning)

Change-Id: I71ebc95fe2fead344c305b7b505573378892c155
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Nov 6, 2012
1 parent cf52582 commit d1972eb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Expand Up @@ -354,7 +354,7 @@ public abstract class AbstractAtomContainerTest extends AbstractChemObjectTest {
* Unit test to ensure that the stereo elements remain intact on cloning a
* container. This test ensures tetrahedral chirality is preserved
*
* @cdk.bug 1###
* @cdk.bug 1264
* @throws Exception
*/
@Test public void testClone_IStereoElement_Tetrahedral() throws Exception {
Expand Down Expand Up @@ -430,7 +430,7 @@ public abstract class AbstractAtomContainerTest extends AbstractChemObjectTest {
* Unit test to ensure that the stereo elements remain intact on cloning a
* container. This test ensures DoubleBondStereochemistry is preserved
*
* @cdk.bug 1###
* @cdk.bug 1264
* @throws Exception
*/
@Test public void testClone_IStereoElement_DoubleBond() throws Exception {
Expand Down Expand Up @@ -496,7 +496,7 @@ public abstract class AbstractAtomContainerTest extends AbstractChemObjectTest {
* Unit test to ensure that the stereo elements remain intact on cloning a
* container. This test ensures AtomParity is preserved
*
* @cdk.bug 1###
* @cdk.bug 1264
* @throws Exception
*/
@Test public void testClone_IStereoElement_AtomParity() throws Exception {
Expand Down Expand Up @@ -821,7 +821,40 @@ public abstract class AbstractAtomContainerTest extends AbstractChemObjectTest {
Assert.assertEquals(0, container.getAtomCount());
Assert.assertEquals(0, container.getBondCount());
}


/**
* Unit test ensures that stereo-elements are removed from a container
* when {@link IAtomContainer#removeAllElements()} is invoked.
* @cdk.bug 1270
*/
@Test public void testRemoveAllElements_StereoElements() {

IAtomContainer container = (IAtomContainer)newChemObject();
container.addStereoElement(new TetrahedralChirality(container.getBuilder().newInstance(IAtom.class),
new IAtom[4],
ITetrahedralChirality.Stereo.CLOCKWISE));

int count = 0;
for (IStereoElement element : container.stereoElements()) {
count++;
}

assertThat("no stereo elements were added", count, is(1));

count = 0;

assertThat("count did not reset", count, is(0));

container.removeAllElements();

for (IStereoElement element : container.stereoElements()) {
count++;
}

assertThat("stereo elements were not removed", count, is(0));

}

@Test public void testRemoveAtom_int() {
IAtomContainer acetone = (IAtomContainer)newChemObject();
IAtom c1 = acetone.getBuilder().newInstance(IAtom.class,"C");
Expand Down
Expand Up @@ -72,6 +72,23 @@ public static void setup() throws Exception {
};
}

/**
* Unit test ensures an exception is thrown if more the two elements are
* passed to the constructor. When IDoubleBondStereoChemistry.getBonds()
* is invoked the fixed size array is copied to an array of size 2. If
* more then 2 bonds are given they would be truncated.
*
* @cdk.bug 1273
*/
@Test(expected = IllegalArgumentException.class)
public void testConstructor_TooManyBonds() {

IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();

new DoubleBondStereochemistry(builder.newInstance(IBond.class),
new IBond[3], Conformation.OPPOSITE);
}

@Test
public void testConstructor() {
DoubleBondStereochemistry stereo = new DoubleBondStereochemistry(
Expand Down

0 comments on commit d1972eb

Please sign in to comment.