Skip to content

Commit

Permalink
A few missing unit tests in the 'qsar' module
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 25, 2011
1 parent 804a6f5 commit 2356a10
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/main/org/openscience/cdk/tools/AtomicProperties.java
Expand Up @@ -27,6 +27,9 @@
import java.util.Hashtable;
import java.util.Map;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;

/**
* Provides atomic property values for descriptor calculations.
*
Expand All @@ -37,6 +40,7 @@
* @cdk.module qsar
* @cdk.githash
*/
@TestClass("org.openscience.cdk.tools.AtomicPropertiesTest")
public class AtomicProperties {

private static AtomicProperties ap=null;
Expand Down Expand Up @@ -72,41 +76,47 @@ private AtomicProperties() throws IOException {
bufferedReader.close();
}



@TestMethod("testGetVdWVolume")
public double getVdWVolume(String symbol) {
return htVdWVolume.get(symbol);
}

@TestMethod("testGetNormalizedVdWVolume")
public double getNormalizedVdWVolume(String symbol) {
return this.getVdWVolume(symbol)/this.getVdWVolume("C");
}

@TestMethod("testGetElectronegativity")
public double getElectronegativity(String symbol) {
return htElectronegativity.get(symbol);
}

@TestMethod("testGetNormalizedElectronegativity")
public double getNormalizedElectronegativity(String symbol) {
return this.getElectronegativity(symbol)/this.getElectronegativity("C");
}
public double getPolarizability(String symbol) {

@TestMethod("testGetPolarizability")
public double getPolarizability(String symbol) {
return htPolarizability.get(symbol);
}

@TestMethod("testGetNormalizedPolarizability")
public double getNormalizedPolarizability(String symbol) {
return this.getPolarizability(symbol)/this.getPolarizability("C");
}

@TestMethod("testGetMass")
public double getMass(String symbol) {
return htMass.get(symbol);
}

@TestMethod("testGetNormalizedMass")
public double getNormalizedMass(String symbol) {
return this.getMass(symbol)/this.getMass("C");
}



@TestMethod("testGetInstance")
public static AtomicProperties getInstance() throws IOException
{
if (ap == null) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/org/openscience/cdk/modulesuites/MqsarTests.java
Expand Up @@ -23,6 +23,7 @@
import org.junit.runners.Suite.SuiteClasses;
import org.openscience.cdk.coverage.QsarCoverageTest;
import org.openscience.cdk.qsar.DescriptorExceptionTest;
import org.openscience.cdk.tools.AtomicPropertiesTest;

/**
* TestSuite that runs all the sample tests.
Expand All @@ -34,6 +35,7 @@
@RunWith(value=Suite.class)
@SuiteClasses(value={
QsarCoverageTest.class,
DescriptorExceptionTest.class
DescriptorExceptionTest.class,
AtomicPropertiesTest.class
})
public class MqsarTests {}
101 changes: 101 additions & 0 deletions src/test/org/openscience/cdk/tools/AtomicPropertiesTest.java
@@ -0,0 +1,101 @@
/* Copyright (C) 2011 Egon Willighagen <egonw@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 I ask is that proper credit is given for my 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.tools;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;

/**
* @cdk.module test-qsar
*/
public class AtomicPropertiesTest extends CDKTestCase {

@Test
public void testGetInstance() throws IOException {
AtomicProperties props = AtomicProperties.getInstance();
Assert.assertNotNull(props);
// test singleton pattern
AtomicProperties props2 = AtomicProperties.getInstance();
Assert.assertEquals(props2, props);
}

@Test
public void testGetMass() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double mass = props.getMass("C");
Assert.assertTrue(mass > 0);
}

@Test
public void testGetNormalizedMass() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double mass = props.getNormalizedMass("C");
Assert.assertTrue(mass > 0);
}

@Test
public void testGetPolarizability() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double polar = props.getPolarizability("C");
Assert.assertTrue(polar > 0);
}

@Test
public void testGetNormalizedPolarizability() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double polar = props.getNormalizedPolarizability("C");
Assert.assertTrue(polar > 0);
}

@Test
public void testGetVdWVolume() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double vol = props.getVdWVolume("C");
Assert.assertTrue(vol > 0);
}

@Test
public void testGetNormalizedVdWVolume() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double vol = props.getNormalizedVdWVolume("C");
Assert.assertTrue(vol > 0);
}

@Test
public void testGetElectronegativity() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double eneg = props.getElectronegativity("C");
Assert.assertTrue(eneg > 0);
}

@Test
public void testGetNormalizedElectronegativity() throws Exception {
AtomicProperties props = AtomicProperties.getInstance();
double eneg = props.getNormalizedElectronegativity("C");
Assert.assertTrue(eneg > 0);
}
}

0 comments on commit 2356a10

Please sign in to comment.