1 /* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project 2 * 3 * Contact: cdk-devel@lists.sourceforge.net 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; either version 2.1 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 package org.openscience.cdk.qsar.descriptors.molecular; 20 21 import org.junit.Assert; 22 import org.junit.Before; 23 import org.junit.Test; 24 import org.openscience.cdk.DefaultChemObjectBuilder; 25 import org.openscience.cdk.interfaces.IAtomContainer; 26 import org.openscience.cdk.qsar.result.DoubleArrayResult; 27 import org.openscience.cdk.smiles.SmilesParser; 28 import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; 29 30 /** 31 * @cdk.module test-qsarmolecular 32 */ 33 public class WienerNumbersDescriptorTest extends MolecularDescriptorTest { 34 WienerNumbersDescriptorTest()35 public WienerNumbersDescriptorTest() {} 36 37 @Before setUp()38 public void setUp() throws Exception { 39 setDescriptor(WienerNumbersDescriptor.class); 40 } 41 42 @Test testWienerNumbersDescriptor()43 public void testWienerNumbersDescriptor() throws Exception { 44 double[] testResult = {18, 2}; 45 SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); 46 IAtomContainer mol = sp.parseSmiles("[H]C([H])([H])C([H])([H])C(=O)O"); 47 AtomContainerManipulator.removeHydrogens(mol); 48 DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(mol).getValue(); 49 Assert.assertEquals(testResult[0], retval.get(0), 0.0001); 50 Assert.assertEquals(testResult[1], retval.get(1), 0.0001); 51 } 52 53 /** 54 * Test if the descriptor returns the same results with and without explicit hydrogens. 55 */ 56 @Test testWithExplicitHydrogens()57 public void testWithExplicitHydrogens() throws Exception { 58 double[] testResult = {18, 2}; 59 SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); 60 IAtomContainer mol = sp.parseSmiles("[H]C([H])([H])C([H])([H])C(=O)O"); 61 DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(mol).getValue(); 62 Assert.assertEquals(testResult[0], retval.get(0), 0.0001); 63 Assert.assertEquals(testResult[1], retval.get(1), 0.0001); 64 } 65 66 /** 67 * Numbers extracted from {@cdk.cite Wiener1947}. 68 */ 69 @Test testOriginalWienerPaperCompounds()70 public void testOriginalWienerPaperCompounds() throws Exception { 71 SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); 72 double[] testResult = {10, 20, 35, 56, 84, 120, 165, 220, 286}; 73 String smiles = "CCC"; 74 for (int i = 0; i < testResult.length; i++) { 75 smiles += "C"; // create the matching paraffin 76 IAtomContainer mol = sp.parseSmiles(smiles); 77 DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(mol).getValue(); 78 Assert.assertEquals(testResult[i], retval.get(0), 0.0001); 79 } 80 } 81 } 82