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.exception.CDKException;
26 import org.openscience.cdk.interfaces.IAtomContainer;
27 import org.openscience.cdk.qsar.DescriptorValue;
28 import org.openscience.cdk.qsar.result.IntegerResult;
29 import org.openscience.cdk.smiles.SmilesParser;
30 
31 /**
32  * TestSuite that runs a test for the AtomCountDescriptor.
33  *
34  * @cdk.module test-qsarmolecular
35  */
36 
37 public class AtomCountDescriptorTest extends MolecularDescriptorTest {
38 
AtomCountDescriptorTest()39     public AtomCountDescriptorTest() {}
40 
41     @Before
setUp()42     public void setUp() throws Exception {
43         setDescriptor(AtomCountDescriptor.class);
44     }
45 
46     @Test
testCarbonCount()47     public void testCarbonCount() throws ClassNotFoundException, CDKException, java.lang.Exception {
48         Object[] params = {"C"};
49         descriptor.setParameters(params);
50         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
51         IAtomContainer mol = sp.parseSmiles("CCO"); // ethanol
52         DescriptorValue value = descriptor.calculate(mol);
53         Assert.assertEquals(2, ((IntegerResult) value.getValue()).intValue());
54         Assert.assertEquals(1, value.getNames().length);
55         Assert.assertEquals("nC", value.getNames()[0]);
56         Assert.assertEquals(descriptor.getDescriptorNames()[0], value.getNames()[0]);
57     }
58 
59     @Test
testImplicitExplicitH()60     public void testImplicitExplicitH() throws Exception {
61         Object[] params = {"*"};
62         descriptor.setParameters(params);
63         SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
64         IAtomContainer mol = sp.parseSmiles("C"); // ethanol
65         DescriptorValue value = descriptor.calculate(mol);
66         Assert.assertEquals(5, ((IntegerResult) value.getValue()).intValue());
67 
68         mol = sp.parseSmiles("[C]"); // ethanol
69         value = descriptor.calculate(mol);
70         Assert.assertEquals(1, ((IntegerResult) value.getValue()).intValue());
71     }
72 }
73