Skip to content

Commit

Permalink
Added unit test and annotation for moment generation (3D Similarity)
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Jan 30, 2013
1 parent f4b625f commit d527061
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -88,6 +88,7 @@ private static float mu3(double[] x, double mean, double sigma) {
* @return A 12 element array containing the descriptors.
* @throws CDKException if there are no 3D coordinates
*/
@TestMethod("testGenerateMoments")
public static float[] generateMoments(IAtomContainer atomContainer) throws CDKException {
// lets check if we have 3D coordinates
Iterator<IAtom> atoms;
Expand Down
17 changes: 17 additions & 0 deletions src/test/org/openscience/cdk/similarity/DistanceMomentTest.java
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
Expand Down Expand Up @@ -38,6 +39,22 @@ public void test3DSim1() throws Exception {
Assert.assertEquals(1.0000, sim, 0.00001);
}

@Test
public void testGenerateMoments() throws Exception {
String filename = "data/mdl/sim3d1.sdf";
IAtomContainer ac = loadMolecule(filename);
float[] expected = new float[]{ 3.710034f, 1.780116f, 0.26535583f, 3.7945938f,
2.2801101f, 0.20164771f, 7.1209f, 9.234152f,
-0.49032924f, 6.6067924f, 8.89391f, -0.048539735f};
float[] actual = DistanceMoment.generateMoments(ac);

// no assertArrayEquals for junit 4.5
for(int i = 0; i < expected.length; i++){
Assert.assertEquals(expected[i], actual[i], 0.000001);
}

}

@Test
public void test3DSim2() throws Exception {
IAtomContainer ac1 = loadMolecule("data/mdl/sim3d1.sdf");
Expand Down

0 comments on commit d527061

Please sign in to comment.