Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for methods related to ShortestPathFingerprint. This …
…include unit test for RandomNumber, SimpleAtomComparator, SimpleAtomCanonicalisation.
- Loading branch information
Showing
6 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/org/openscience/cdk/fingerprint/RandomNumberTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2012 John May <jwmay@users.sf.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.fingerprint; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for the {@link RandomNumber}. | ||
* | ||
* @author John May | ||
* @cdk.module test-fingerprint | ||
*/ | ||
public class RandomNumberTest { | ||
|
||
private RandomNumber rn = new RandomNumber(); | ||
|
||
/** | ||
* Tests the pseudorandom number generation to make sure we alway generate | ||
* the same "next" random number. | ||
*/ | ||
@Test | ||
public void testGenerateMersenneTwisterRandomNumber() { | ||
|
||
Assert.assertEquals("Expected next random number to be 444", | ||
444, | ||
rn.generateMersenneTwisterRandomNumber(1024, 42)); | ||
Assert.assertEquals("Expected next random number to be 748", | ||
748, | ||
rn.generateMersenneTwisterRandomNumber(1024, 444)); | ||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/test/org/openscience/cdk/fingerprint/SimpleAtomCanonicalizationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.openscience.cdk.fingerprint; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openscience.cdk.exception.CDKException; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.interfaces.IAtomType; | ||
import org.openscience.cdk.templates.MoleculeFactory; | ||
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* @author John May | ||
* @cdk.module test-fingerprint | ||
*/ | ||
public class SimpleAtomCanonicalizationTest { | ||
|
||
@Test public void testCanonicalizeAtoms() throws CDKException { | ||
|
||
IAtomContainer container = MoleculeFactory.makeAdenine(); | ||
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container); | ||
|
||
Collection<IAtom> atoms = new SimpleAtomCanonicalisation().canonicalizeAtoms(container); | ||
|
||
List<IAtom> mutable = new ArrayList<IAtom>(atoms); | ||
for(IAtom atom : mutable.subList(0, 5)){ | ||
Assert.assertEquals("expect sp2 carbons in first 4 entries", | ||
"C", atom.getSymbol()); | ||
Assert.assertEquals("expect sp2 carbons in first 4 entries", | ||
IAtomType.Hybridization.SP2, atom.getHybridization()); | ||
} | ||
for(IAtom atom : mutable.subList(5, 8)){ | ||
Assert.assertEquals("expect sp2 nitrogen at indices 5-7", | ||
"N", atom.getSymbol()); | ||
Assert.assertEquals("expect sp2 nitrogen at indices 5-7", | ||
IAtomType.Hybridization.SP2, atom.getHybridization()); | ||
} | ||
|
||
Assert.assertEquals("expect nitrogen at indices 8", | ||
"N", mutable.get(8).getSymbol()); | ||
Assert.assertEquals("expect sp3 nitrogen at indices 8", | ||
IAtomType.Hybridization.SP3, | ||
mutable.get(8).getHybridization()); | ||
|
||
Assert.assertEquals("expect nitrogen at indices 9", | ||
"N", mutable.get(9).getSymbol()); | ||
Assert.assertEquals("expect sp3 nitrogen at indices 9", | ||
IAtomType.Hybridization.PLANAR3, | ||
mutable.get(9).getHybridization()); | ||
|
||
} | ||
|
||
|
||
} |
85 changes: 85 additions & 0 deletions
85
src/test/org/openscience/cdk/fingerprint/SimpleAtomComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.openscience.cdk.fingerprint; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openscience.cdk.DefaultChemObjectBuilder; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomType; | ||
import org.openscience.cdk.interfaces.IChemObjectBuilder; | ||
|
||
/** | ||
* @author John May | ||
* @cdk.module test-fingerprint | ||
*/ | ||
public class SimpleAtomComparatorTest { | ||
|
||
private IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); | ||
|
||
@Test | ||
public void testCompare_NullHybridization() throws Exception { | ||
|
||
SimpleAtomComparator comparator = new SimpleAtomComparator(); | ||
|
||
IAtom a1 = builder.newInstance(IAtom.class, "C"); | ||
IAtom a2 = builder.newInstance(IAtom.class, "C"); | ||
|
||
Assert.assertEquals("Null hybridzation should be equals", | ||
0, | ||
comparator.compare(a1, a2)); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompare_SameHybridization() throws Exception { | ||
|
||
SimpleAtomComparator comparator = new SimpleAtomComparator(); | ||
|
||
IAtom a1 = builder.newInstance(IAtom.class, "C"); | ||
IAtom a2 = builder.newInstance(IAtom.class, "C"); | ||
|
||
a1.setHybridization(IAtomType.Hybridization.SP3); | ||
a2.setHybridization(IAtomType.Hybridization.SP3); | ||
|
||
Assert.assertEquals("Same hybridzation should be equals", | ||
0, | ||
comparator.compare(a1, a2)); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompare_DifferentHybridization() throws Exception { | ||
|
||
SimpleAtomComparator comparator = new SimpleAtomComparator(); | ||
|
||
IAtom a1 = builder.newInstance(IAtom.class, "C"); | ||
IAtom a2 = builder.newInstance(IAtom.class, "C"); | ||
|
||
a1.setHybridization(IAtomType.Hybridization.SP2); | ||
a2.setHybridization(IAtomType.Hybridization.SP3); | ||
|
||
Assert.assertEquals("Atom 2 should have priority", | ||
-1, | ||
comparator.compare(a1, a2)); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompare_DifferentSymbol() throws Exception { | ||
|
||
SimpleAtomComparator comparator = new SimpleAtomComparator(); | ||
|
||
IAtom a1 = builder.newInstance(IAtom.class, "C"); | ||
IAtom a2 = builder.newInstance(IAtom.class, "O"); | ||
|
||
|
||
// can't do less than correctly without hamcrest? | ||
Assert.assertTrue("oxygen should rank above carbon", | ||
comparator.compare(a1, a2) < 0); | ||
Assert.assertTrue("oxygen should rank above carbon (inverse)", | ||
comparator.compare(a2, a1) > 0); | ||
|
||
} | ||
|
||
|
||
|
||
} |