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