1 /* Copyright (C) 2008 Miguel Rojas <miguelrojasch@yahoo.es> 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.charges; 20 21 import org.junit.Assert; 22 import org.junit.Test; 23 import org.openscience.cdk.Atom; 24 import org.openscience.cdk.CDKTestCase; 25 import org.openscience.cdk.interfaces.IBond; 26 import org.openscience.cdk.interfaces.IAtomContainer; 27 import org.openscience.cdk.interfaces.IChemObjectBuilder; 28 import org.openscience.cdk.silent.SilentChemObjectBuilder; 29 import org.openscience.cdk.tools.LonePairElectronChecker; 30 import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; 31 32 /** 33 * TestSuite that runs all tests. 34 * 35 * @cdk.module test-charges 36 */ 37 public class PiElectronegativityTest extends CDKTestCase { 38 39 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance(); 40 private LonePairElectronChecker lpcheck = new LonePairElectronChecker(); 41 42 /** 43 * Constructor of the PiElectronegativityTest. 44 */ PiElectronegativityTest()45 public PiElectronegativityTest() { 46 super(); 47 } 48 49 /** 50 * A unit test suite for JUnit. 51 * 52 * @return The test suite 53 */ 54 @Test testPiElectronegativity()55 public void testPiElectronegativity() { 56 57 Assert.assertNotNull(new PiElectronegativity()); 58 } 59 60 /** 61 * A unit test suite for JUnit. 62 * 63 * @return The test suite 64 */ 65 @Test testPiElectronegativity_Int_Int()66 public void testPiElectronegativity_Int_Int() { 67 68 Assert.assertNotNull(new PiElectronegativity(6, 50)); 69 } 70 71 /** 72 * A unit test suite for JUnit. 73 * 74 * @cdk.inchi InChI=1/C4H8/c1-3-4-2/h3H,1,4H2,2H3 75 * 76 * @return The test suite 77 * @throws Exception 78 */ 79 @Test testCalculatePiElectronegativity_IAtomContainer_IAtom()80 public void testCalculatePiElectronegativity_IAtomContainer_IAtom() throws Exception { 81 82 PiElectronegativity pe = new PiElectronegativity(); 83 84 IAtomContainer molecule = builder.newInstance(IAtomContainer.class); 85 molecule.addAtom(new Atom("F")); 86 molecule.addAtom(new Atom("C")); 87 molecule.addBond(0, 1, IBond.Order.SINGLE); 88 89 addExplicitHydrogens(molecule); 90 AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); 91 lpcheck.saturate(molecule); 92 93 for (int i = 0; i < molecule.getAtomCount(); i++) { 94 if (i == 0) 95 Assert.assertNotSame(0.0, pe.calculatePiElectronegativity(molecule, molecule.getAtom(i))); 96 else 97 Assert.assertEquals(0.0, pe.calculatePiElectronegativity(molecule, molecule.getAtom(i)), 0.001); 98 99 } 100 } 101 102 /** 103 * A unit test suite for JUnit. 104 * 105 * @cdk.inchi InChI=1/C4H8/c1-3-4-2/h3H,1,4H2,2H3 106 * 107 * @return The test suite 108 * @throws Exception 109 */ 110 @Test testCalculatePiElectronegativity_IAtomContainer_IAtom_Int_Int()111 public void testCalculatePiElectronegativity_IAtomContainer_IAtom_Int_Int() throws Exception { 112 113 PiElectronegativity pe = new PiElectronegativity(); 114 115 IAtomContainer molecule = builder.newInstance(IAtomContainer.class); 116 molecule.addAtom(new Atom("F")); 117 molecule.addAtom(new Atom("C")); 118 molecule.addBond(0, 1, IBond.Order.SINGLE); 119 120 addExplicitHydrogens(molecule); 121 AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); 122 lpcheck.saturate(molecule); 123 124 for (int i = 0; i < molecule.getAtomCount(); i++) { 125 if (i == 0) 126 Assert.assertNotSame(0.0, pe.calculatePiElectronegativity(molecule, molecule.getAtom(i), 6, 50)); 127 else 128 Assert.assertEquals(0.0, pe.calculatePiElectronegativity(molecule, molecule.getAtom(i), 6, 50), 0.001); 129 130 } 131 } 132 133 /** 134 * A unit test suite for JUnit. 135 * 136 * @return The test suite 137 * @throws Exception 138 */ 139 @Test testGetMaxIterations()140 public void testGetMaxIterations() throws Exception { 141 142 PiElectronegativity pe = new PiElectronegativity(); 143 Assert.assertSame(6, pe.getMaxIterations()); 144 } 145 146 /** 147 * A unit test suite for JUnit. 148 * 149 * @return The test suite 150 * @throws Exception 151 */ 152 @Test testGetMaxResonStruc()153 public void testGetMaxResonStruc() throws Exception { 154 155 PiElectronegativity pe = new PiElectronegativity(); 156 Assert.assertSame(50, pe.getMaxResonStruc()); 157 } 158 159 /** 160 * A unit test suite for JUnit. 161 * 162 * @return The test suite 163 * @throws Exception 164 */ 165 @Test testSetMaxIterations_Int()166 public void testSetMaxIterations_Int() throws Exception { 167 168 PiElectronegativity pe = new PiElectronegativity(); 169 int maxIter = 10; 170 pe.setMaxIterations(maxIter); 171 Assert.assertSame(maxIter, pe.getMaxIterations()); 172 } 173 174 /** 175 * A unit test suite for JUnit. 176 * 177 * @return The test suite 178 * @throws Exception 179 */ 180 @Test testSetMaxResonStruc_Int()181 public void testSetMaxResonStruc_Int() throws Exception { 182 183 PiElectronegativity pe = new PiElectronegativity(); 184 int maxRes = 10; 185 pe.setMaxResonStruc(maxRes); 186 Assert.assertSame(maxRes, pe.getMaxResonStruc()); 187 } 188 } 189