Skip to content

Commit

Permalink
Added unit testing
Browse files Browse the repository at this point in the history
Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Nov 19, 2011
1 parent cdc4cbd commit 05216f0
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/org/openscience/cdk/renderer/BoundsCalculator.java
Expand Up @@ -26,6 +26,8 @@

import javax.vecmath.Point2d;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemModel;
Expand All @@ -42,6 +44,7 @@
* @cdk.module renderbasic
* @cdk.githash
*/
@TestClass("org.openscience.cdk.renderer.BoundsCalculatorTest")
public class BoundsCalculator {

/**
Expand All @@ -50,6 +53,7 @@ public class BoundsCalculator {
* @param chemModel the chem model to use
* @return the bounding rectangle of the chem model
*/
@TestMethod("testCalculateBounds_IChemModel")
public static Rectangle2D calculateBounds(IChemModel chemModel) {
IMoleculeSet moleculeSet = chemModel.getMoleculeSet();
IReactionSet reactionSet = chemModel.getReactionSet();
Expand All @@ -75,6 +79,7 @@ public static Rectangle2D calculateBounds(IChemModel chemModel) {
* @param reactionSet the reaction set to use
* @return the bounding rectangle of the reaction set
*/
@TestMethod("testCalculateBounds_IReactionSet")
public static Rectangle2D calculateBounds(IReactionSet reactionSet) {
Rectangle2D totalBounds = new Rectangle2D.Double();
for (IReaction reaction : reactionSet.reactions()) {
Expand All @@ -94,6 +99,7 @@ public static Rectangle2D calculateBounds(IReactionSet reactionSet) {
* @param reaction the reaction to use
* @return the bounding rectangle of the reaction
*/
@TestMethod("testCalculateBounds_IReaction")
public static Rectangle2D calculateBounds(IReaction reaction) {
// get the participants in the reaction
IMoleculeSet reactants = reaction.getReactants();
Expand All @@ -111,6 +117,7 @@ public static Rectangle2D calculateBounds(IReaction reaction) {
* @param moleculeSet the molecule set to use
* @return the bounding rectangle of the molecule set
*/
@TestMethod("testCalculateBounds_IMoleculeSet")
public static Rectangle2D calculateBounds(IMoleculeSet moleculeSet) {
Rectangle2D totalBounds = new Rectangle2D.Double();
for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
Expand All @@ -131,6 +138,7 @@ public static Rectangle2D calculateBounds(IMoleculeSet moleculeSet) {
* @param atomContainer the atom container to use
* @return the bounding rectangle of the atom container
*/
@TestMethod("testCalculateBounds_IAtomContainer")
public static Rectangle2D calculateBounds(IAtomContainer atomContainer) {
// this is essential, otherwise a rectangle
// of (+INF, -INF, +INF, -INF) is returned!
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.RenderbasicCoverageTest;
import org.openscience.cdk.renderer.AtomContainerRendererTest;
import org.openscience.cdk.renderer.BoundsCalculatorTest;
import org.openscience.cdk.renderer.elements.ArrowElementTest;
import org.openscience.cdk.renderer.elements.AtomSymbolElementTest;
import org.openscience.cdk.renderer.elements.GeneralPathTest;
Expand Down Expand Up @@ -69,6 +70,7 @@
LineToTest.class,
CubicToTest.class,
MoveToTest.class,
QuadToTest.class
QuadToTest.class,
BoundsCalculatorTest.class
})
public class MrenderbasicTests {}
185 changes: 185 additions & 0 deletions src/test/org/openscience/cdk/renderer/BoundsCalculatorTest.java
@@ -0,0 +1,185 @@
/* Copyright (C) 2011 Egon Willighagen <egonw@users.sourceforge.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 USA.
*/
package org.openscience.cdk.renderer;

import org.junit.Test;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.openscience.cdk.nonotify.NNAtomContainer;

/**
* @cdk.module test-renderbasic
*/
public class BoundsCalculatorTest {

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IAtomContainer_SingleAtom() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
BoundsCalculator.calculateBounds(container);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IAtomContainer() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
BoundsCalculator.calculateBounds(container);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IMoleculeSet_SingleAtom() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IMoleculeSet set = container.getBuilder().newInstance(IMoleculeSet.class);
set.addAtomContainer(container);
BoundsCalculator.calculateBounds(set);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IMoleculeSet() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IMoleculeSet set = container.getBuilder().newInstance(IMoleculeSet.class);
set.addAtomContainer(container);
BoundsCalculator.calculateBounds(set);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IReactionSet_SingleAtom() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IReaction reaction = container.getBuilder().newInstance(IReaction.class);
reaction.addReactant(
container.getBuilder().newInstance(IMolecule.class, container)
);
IReactionSet set = container.getBuilder().newInstance(IReactionSet.class);
set.addReaction(reaction);
BoundsCalculator.calculateBounds(set);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IReactionSet() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IReaction reaction = container.getBuilder().newInstance(IReaction.class);
reaction.addReactant(
container.getBuilder().newInstance(IMolecule.class, container)
);
IReactionSet set = container.getBuilder().newInstance(IReactionSet.class);
set.addReaction(reaction);
BoundsCalculator.calculateBounds(set);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IChemModel_SingleAtom() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IMoleculeSet set = container.getBuilder().newInstance(IMoleculeSet.class);
set.addAtomContainer(container);
IChemModel model = container.getBuilder().newInstance(IChemModel.class);
model.setMoleculeSet(set);
BoundsCalculator.calculateBounds(model);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IChemModel() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IMoleculeSet set = container.getBuilder().newInstance(IMoleculeSet.class);
set.addAtomContainer(container);
IChemModel model = container.getBuilder().newInstance(IChemModel.class);
model.setMoleculeSet(set);
BoundsCalculator.calculateBounds(model);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IReaction_SingleAtom() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IReaction reaction = container.getBuilder().newInstance(IReaction.class);
reaction.addReactant(
container.getBuilder().newInstance(IMolecule.class, container)
);
BoundsCalculator.calculateBounds(reaction);
}

/**
* Test if we get the expected {@link IllegalArgumentException} when we pass
* an {@link IAtomContainer} without 2D coordinates.
*/
@Test(expected=IllegalArgumentException.class)
public void testCalculateBounds_IReaction() {
IAtomContainer container = new NNAtomContainer();
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
container.addAtom(container.getBuilder().newInstance(IAtom.class, "C"));
IReaction reaction = container.getBuilder().newInstance(IReaction.class);
reaction.addReactant(
container.getBuilder().newInstance(IMolecule.class, container)
);
BoundsCalculator.calculateBounds(reaction);
}
}

0 comments on commit 05216f0

Please sign in to comment.