📄 jumbo46cmlfragmentstest.java
字号:
/* $RCSfile$ * $Author: egonw $ * $Date: 2007-05-05 12:00:36 +0000 (Sa, 05 Mai 2007) $ * $Revision: 8301 $ * * Copyright (C) 2003-2007 The Chemistry Development Kit (CDK) project * * 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 we ask is that proper credit is given for our 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.test.io.cml;import java.io.ByteArrayInputStream;import javax.vecmath.Vector3d;import junit.framework.Test;import junit.framework.TestSuite;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.interfaces.IAtom;import org.openscience.cdk.interfaces.IChemFile;import org.openscience.cdk.io.CMLReader;import org.openscience.cdk.test.CDKTestCase;/** * Atomic tests for the reading CML documents. All tested CML strings are valid CML 2, * as can be determined in cdk/src/org/openscience/cdk/test/io/cml/cmlTestFramework.xml. * * @cdk.module test-io * * @author Egon Willighagen <egonw@sci.kun.nl> */public class Jumbo46CMLFragmentsTest extends CDKTestCase { public Jumbo46CMLFragmentsTest(String name) { super(name); } public static Test suite() { return new TestSuite(Jumbo46CMLFragmentsTest.class); } public void testAtomId() throws Exception { String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/></atomArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(1, mol.getAtomCount()); IAtom atom = mol.getAtom(0); assertEquals("a1", atom.getID()); } public void testAtomId3() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(3, mol.getAtomCount()); IAtom atom = mol.getAtom(1); assertEquals("a2", atom.getID()); } public void testAtomElementType3() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1' elementType='C'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(1, mol.getAtomCount()); IAtom atom = mol.getAtom(0); assertEquals("C", atom.getSymbol()); } public void testBond() throws Exception { String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); assertEquals(2, bond.getAtomCount()); IAtom atom1 = bond.getAtom(0); IAtom atom2 = bond.getAtom(1); assertEquals("a1", atom1.getID()); assertEquals("a2", atom2.getID()); } public void testBond4() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' bondID='b1 b2'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(3, mol.getAtomCount()); assertEquals(2, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); assertEquals(2, bond.getAtomCount()); IAtom atom1 = bond.getAtom(0); IAtom atom2 = bond.getAtom(1); assertEquals("a1", atom1.getID()); assertEquals("a2", atom2.getID()); assertEquals("b2", mol.getBond(1).getID()); } public void testBond5() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2 a3'/><bondArray atomRef1='a1 a1' atomRef2='a2 a3' order='1 1'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(3, mol.getAtomCount()); assertEquals(2, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); assertEquals(2, bond.getAtomCount()); assertEquals(1.0, bond.getOrder(), 0.0001); bond = mol.getBond(1); assertEquals(2, bond.getAtomCount()); assertEquals(1.0, bond.getOrder(), 0.0001); } public void testBondAromatic() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray atomRef1='a1' atomRef2='a2' order='A'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); assertEquals(CDKConstants.BONDORDER_SINGLE, bond.getOrder(), 0.0001); assertEquals(true, bond.getFlag(CDKConstants.ISAROMATIC)); } public void testBondId() throws Exception { String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); org.openscience.cdk.interfaces.IMolecule mol = checkForSingleMoleculeFile(chemFile); assertEquals(2, mol.getAtomCount()); assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); assertEquals("b1", bond.getID()); } public void testList() throws Exception { String cmlString = "<list>" + "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>" + "<molecule id='m2'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>" + "</list>"; IChemFile chemFile = parseCMLString(cmlString); checkForXMoleculeFile(chemFile, 2); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -