1 /* 2 * Copyright (C) 2012 John May <jwmay@users.sf.net> 3 * 4 * Contact: cdk-devel@lists.sourceforge.net 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published by the 8 * Free Software Foundation; either version 2.1 of the License, or (at your 9 * option) any later version. All we ask is that proper credit is given for our 10 * work, which includes - but is not limited to - adding the above copyright 11 * notice to the beginning of your source code files, and to any copyright 12 * notice that you may distribute with programs based on this work. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 17 * for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public License 20 * along with this program; if not, write to the Free Software Foundation, Inc., 21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 */ 23 package org.openscience.cdk.ringsearch; 24 25 import org.junit.Test; 26 import org.openscience.cdk.Atom; 27 import org.openscience.cdk.AtomContainer; 28 import org.openscience.cdk.Bond; 29 import org.openscience.cdk.interfaces.IAtom; 30 import org.openscience.cdk.interfaces.IAtomContainer; 31 import org.openscience.cdk.interfaces.IBond; 32 33 import java.util.List; 34 35 import static org.hamcrest.CoreMatchers.is; 36 import static org.junit.Assert.assertThat; 37 38 /** 39 * benzylbenzene ring search unit tests 40 * 41 * @author John May 42 * @cdk.module test-standard 43 * */ 44 public final class RingSearchTest_BenzylBenzene { 45 46 private final IAtomContainer benzylbenzene = benzylbenzene(); 47 48 @Test testCyclic()49 public void testCyclic() { 50 assertThat(new RingSearch(benzylbenzene).cyclic().length, is(benzylbenzene.getAtomCount() - 1)); 51 } 52 53 @Test testCyclic_Int()54 public void testCyclic_Int() { 55 int n = benzylbenzene.getAtomCount(); 56 RingSearch ringSearch = new RingSearch(benzylbenzene); 57 58 int cyclic = 0, acyclic = 0; 59 for (int i = 0; i < n; i++) { 60 if (ringSearch.cyclic(i)) 61 cyclic++; 62 else 63 acyclic++; 64 } 65 66 // single atom not in a ring 67 assertThat(acyclic, is(1)); 68 assertThat(cyclic, is(n - 1)); 69 70 } 71 72 @Test testIsolated()73 public void testIsolated() { 74 RingSearch search = new RingSearch(benzylbenzene); 75 int[][] isolated = search.isolated(); 76 assertThat(isolated.length, is(2)); 77 assertThat(isolated[0].length, is(6)); 78 assertThat(isolated[1].length, is(6)); 79 } 80 81 @Test testFused()82 public void testFused() { 83 assertThat(new RingSearch(benzylbenzene).fused().length, is(0)); 84 } 85 86 @Test testRingFragments()87 public void testRingFragments() { 88 IAtomContainer fragment = new RingSearch(benzylbenzene).ringFragments(); 89 assertThat(fragment.getAtomCount(), is(benzylbenzene.getAtomCount() - 1)); 90 assertThat(fragment.getBondCount(), is(benzylbenzene.getBondCount() - 2)); 91 } 92 93 @Test testIsolatedRingFragments()94 public void testIsolatedRingFragments() { 95 RingSearch search = new RingSearch(benzylbenzene); 96 List<IAtomContainer> isolated = search.isolatedRingFragments(); 97 assertThat(isolated.size(), is(2)); 98 assertThat(isolated.get(0).getAtomCount(), is(6)); 99 assertThat(isolated.get(0).getBondCount(), is(6)); 100 assertThat(isolated.get(1).getAtomCount(), is(6)); 101 assertThat(isolated.get(1).getBondCount(), is(6)); 102 } 103 104 @Test testFusedRingFragments()105 public void testFusedRingFragments() { 106 RingSearch search = new RingSearch(benzylbenzene); 107 List<IAtomContainer> fused = search.fusedRingFragments(); 108 assertThat(fused.size(), is(0)); 109 } 110 111 /** 112 * @cdk.inchi InChI=1S/C13H12/c1-3-7-12(8-4-1)11-13-9-5-2-6-10-13/h1-10H,11H2 113 */ benzylbenzene()114 public static IAtomContainer benzylbenzene() { 115 IAtomContainer mol = new AtomContainer(); 116 IAtom a1 = new Atom("C"); 117 mol.addAtom(a1); 118 IAtom a2 = new Atom("C"); 119 mol.addAtom(a2); 120 IAtom a3 = new Atom("C"); 121 mol.addAtom(a3); 122 IAtom a4 = new Atom("C"); 123 mol.addAtom(a4); 124 IAtom a5 = new Atom("C"); 125 mol.addAtom(a5); 126 IAtom a6 = new Atom("C"); 127 mol.addAtom(a6); 128 IAtom a7 = new Atom("C"); 129 mol.addAtom(a7); 130 IAtom a8 = new Atom("C"); 131 mol.addAtom(a8); 132 IAtom a9 = new Atom("C"); 133 mol.addAtom(a9); 134 IAtom a10 = new Atom("C"); 135 mol.addAtom(a10); 136 IAtom a11 = new Atom("C"); 137 mol.addAtom(a11); 138 IAtom a12 = new Atom("C"); 139 mol.addAtom(a12); 140 IAtom a13 = new Atom("C"); 141 mol.addAtom(a13); 142 IBond b1 = new Bond(a6, a7, IBond.Order.SINGLE); 143 mol.addBond(b1); 144 IBond b2 = new Bond(a7, a8, IBond.Order.SINGLE); 145 mol.addBond(b2); 146 IBond b3 = new Bond(a6, a5, IBond.Order.SINGLE); 147 mol.addBond(b3); 148 IBond b4 = new Bond(a5, a4, IBond.Order.DOUBLE); 149 mol.addBond(b4); 150 IBond b5 = new Bond(a4, a3, IBond.Order.SINGLE); 151 mol.addBond(b5); 152 IBond b6 = new Bond(a3, a2, IBond.Order.DOUBLE); 153 mol.addBond(b6); 154 IBond b7 = new Bond(a6, a1, IBond.Order.DOUBLE); 155 mol.addBond(b7); 156 IBond b8 = new Bond(a2, a1, IBond.Order.SINGLE); 157 mol.addBond(b8); 158 IBond b9 = new Bond(a10, a11, IBond.Order.DOUBLE); 159 mol.addBond(b9); 160 IBond b10 = new Bond(a10, a9, IBond.Order.SINGLE); 161 mol.addBond(b10); 162 IBond b11 = new Bond(a9, a8, IBond.Order.DOUBLE); 163 mol.addBond(b11); 164 IBond b12 = new Bond(a8, a13, IBond.Order.SINGLE); 165 mol.addBond(b12); 166 IBond b13 = new Bond(a13, a12, IBond.Order.DOUBLE); 167 mol.addBond(b13); 168 IBond b14 = new Bond(a12, a11, IBond.Order.SINGLE); 169 mol.addBond(b14); 170 return mol; 171 } 172 173 } 174