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.interfaces.IAtomContainer; 27 import org.openscience.cdk.templates.TestMoleculeFactory; 28 29 import java.util.List; 30 31 import static org.hamcrest.CoreMatchers.anyOf; 32 import static org.hamcrest.CoreMatchers.is; 33 import static org.junit.Assert.assertThat; 34 import static org.junit.Assert.assertTrue; 35 36 /** 37 * ring search unit tests for spiro rings 38 * 39 * @author John May 40 * @cdk.module test-standard 41 */ 42 public final class RingSearchTest_SpiroRings { 43 44 private final IAtomContainer spiro = TestMoleculeFactory.makeSpiroRings(); 45 46 @Test testCyclic()47 public void testCyclic() { 48 assertThat(new RingSearch(spiro).cyclic().length, is(spiro.getAtomCount())); 49 } 50 51 @Test testCyclic_Int()52 public void testCyclic_Int() { 53 int n = spiro.getAtomCount(); 54 RingSearch ringSearch = new RingSearch(spiro); 55 for (int i = 0; i < n; i++) { 56 assertTrue(ringSearch.cyclic(i)); 57 } 58 } 59 60 @Test testIsolated()61 public void testIsolated() { 62 RingSearch search = new RingSearch(spiro); 63 int[][] isolated = search.isolated(); 64 assertThat(isolated.length, is(2)); 65 assertThat(4, anyOf(is(isolated[0].length), is(isolated[1].length))); 66 assertThat(7, anyOf(is(isolated[0].length), is(isolated[1].length))); 67 } 68 69 @Test testFused()70 public void testFused() { 71 assertThat(new RingSearch(spiro).fused().length, is(0)); 72 } 73 74 @Test testRingFragments()75 public void testRingFragments() { 76 IAtomContainer fragment = new RingSearch(spiro).ringFragments(); 77 assertThat(fragment.getAtomCount(), is(spiro.getAtomCount())); 78 assertThat(fragment.getBondCount(), is(spiro.getBondCount())); 79 } 80 81 @Test testIsolatedRingFragments()82 public void testIsolatedRingFragments() { 83 RingSearch search = new RingSearch(spiro); 84 List<IAtomContainer> isolated = search.isolatedRingFragments(); 85 assertThat(isolated.size(), is(2)); 86 assertThat(4, anyOf(is(isolated.get(0).getAtomCount()), is(isolated.get(1).getAtomCount()))); 87 assertThat(7, anyOf(is(isolated.get(0).getAtomCount()), is(isolated.get(1).getAtomCount()))); 88 } 89 90 @Test testFusedRingFragments()91 public void testFusedRingFragments() { 92 RingSearch search = new RingSearch(spiro); 93 List<IAtomContainer> fused = search.fusedRingFragments(); 94 assertThat(fused.size(), is(0)); 95 } 96 97 } 98