1 /* 2 * Copyright (c) 2013 European Bioinformatics Institute (EMBL-EBI) 3 * John May <jwmay@users.sf.net> 4 * 5 * Contact: cdk-devel@lists.sourceforge.net 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation; either version 2.1 of the License, or (at 10 * your option) any later version. All we ask is that proper credit is given 11 * for our work, which includes - but is not limited to - adding the above 12 * copyright notice to the beginning of your source code files, and to any 13 * copyright notice that you may distribute with programs based on this work. 14 * 15 * This program is distributed in the hope that it will be useful, but WITHOUT 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 * License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U 23 */ 24 25 package org.openscience.cdk.isomorphism; 26 27 import org.junit.Test; 28 import org.openscience.cdk.interfaces.IBond; 29 import org.openscience.cdk.isomorphism.matchers.IQueryBond; 30 31 import static org.junit.Assert.assertFalse; 32 import static org.junit.Assert.assertTrue; 33 import static org.mockito.Mockito.mock; 34 import static org.mockito.Mockito.when; 35 import static org.openscience.cdk.CDKConstants.ISAROMATIC; 36 37 /** 38 * @author John May 39 * @cdk.module test-isomorphism 40 */ 41 public class BondMatcherTest { 42 43 @Test anyMatch()44 public void anyMatch() { 45 BondMatcher matcher = BondMatcher.forAny(); 46 IBond bond1 = mock(IBond.class); 47 IBond bond2 = mock(IBond.class); 48 IBond bond3 = mock(IBond.class); 49 assertTrue(matcher.matches(bond1, bond2)); 50 assertTrue(matcher.matches(bond2, bond1)); 51 assertTrue(matcher.matches(bond1, bond3)); 52 assertTrue(matcher.matches(bond1, null)); 53 assertTrue(matcher.matches(null, null)); 54 } 55 56 @Test aromaticMatch()57 public void aromaticMatch() { 58 BondMatcher matcher = BondMatcher.forOrder(); 59 IBond bond1 = mock(IBond.class); 60 IBond bond2 = mock(IBond.class); 61 when(bond1.getFlag(ISAROMATIC)).thenReturn(true); 62 when(bond2.getFlag(ISAROMATIC)).thenReturn(true); 63 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 64 when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); 65 assertTrue(matcher.matches(bond1, bond2)); 66 assertTrue(matcher.matches(bond2, bond1)); 67 } 68 69 @Test aliphaticMatch()70 public void aliphaticMatch() { 71 BondMatcher matcher = BondMatcher.forOrder(); 72 IBond bond1 = mock(IBond.class); 73 IBond bond2 = mock(IBond.class); 74 when(bond1.getFlag(ISAROMATIC)).thenReturn(false); 75 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 76 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 77 when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); 78 assertTrue(matcher.matches(bond1, bond2)); 79 assertTrue(matcher.matches(bond2, bond1)); 80 } 81 82 @Test aromaticStrictMatch()83 public void aromaticStrictMatch() { 84 BondMatcher matcher = BondMatcher.forStrictOrder(); 85 IBond bond1 = mock(IBond.class); 86 IBond bond2 = mock(IBond.class); 87 when(bond1.getFlag(ISAROMATIC)).thenReturn(true); 88 when(bond2.getFlag(ISAROMATIC)).thenReturn(true); 89 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 90 when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); 91 assertTrue(matcher.matches(bond1, bond2)); 92 assertTrue(matcher.matches(bond2, bond1)); 93 } 94 95 @Test aliphaticStrictMatch()96 public void aliphaticStrictMatch() { 97 BondMatcher matcher = BondMatcher.forStrictOrder(); 98 IBond bond1 = mock(IBond.class); 99 IBond bond2 = mock(IBond.class); 100 when(bond1.getFlag(ISAROMATIC)).thenReturn(false); 101 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 102 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 103 when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); 104 assertTrue(matcher.matches(bond1, bond2)); 105 assertTrue(matcher.matches(bond2, bond1)); 106 } 107 108 @Test aliphaticMismatch_aromatic()109 public void aliphaticMismatch_aromatic() { 110 BondMatcher matcher = BondMatcher.forOrder(); 111 IBond bond1 = mock(IBond.class); 112 IBond bond2 = mock(IBond.class); 113 when(bond1.getFlag(ISAROMATIC)).thenReturn(true); 114 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 115 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 116 when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); 117 assertTrue(matcher.matches(bond1, bond2)); 118 assertTrue(matcher.matches(bond2, bond1)); 119 } 120 121 @Test aliphaticStrictMismatch_aromatic()122 public void aliphaticStrictMismatch_aromatic() { 123 BondMatcher matcher = BondMatcher.forStrictOrder(); 124 IBond bond1 = mock(IBond.class); 125 IBond bond2 = mock(IBond.class); 126 when(bond1.getFlag(ISAROMATIC)).thenReturn(true); 127 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 128 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 129 when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); 130 assertFalse(matcher.matches(bond1, bond2)); 131 assertFalse(matcher.matches(bond2, bond1)); 132 } 133 134 @Test aliphaticMismatch_order()135 public void aliphaticMismatch_order() { 136 BondMatcher matcher = BondMatcher.forOrder(); 137 IBond bond1 = mock(IBond.class); 138 IBond bond2 = mock(IBond.class); 139 when(bond1.getFlag(ISAROMATIC)).thenReturn(false); 140 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 141 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 142 when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); 143 assertFalse(matcher.matches(bond1, bond2)); 144 assertFalse(matcher.matches(bond2, bond1)); 145 } 146 147 @Test aliphaticStrictMismatch_order()148 public void aliphaticStrictMismatch_order() { 149 BondMatcher matcher = BondMatcher.forStrictOrder(); 150 IBond bond1 = mock(IBond.class); 151 IBond bond2 = mock(IBond.class); 152 when(bond1.getFlag(ISAROMATIC)).thenReturn(false); 153 when(bond2.getFlag(ISAROMATIC)).thenReturn(false); 154 when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); 155 when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); 156 assertFalse(matcher.matches(bond1, bond2)); 157 assertFalse(matcher.matches(bond2, bond1)); 158 } 159 160 @Test queryMatch()161 public void queryMatch() { 162 BondMatcher matcher = BondMatcher.forQuery(); 163 IQueryBond bond1 = mock(IQueryBond.class); 164 IBond bond2 = mock(IBond.class); 165 IBond bond3 = mock(IBond.class); 166 when(bond1.matches(bond2)).thenReturn(true); 167 when(bond1.matches(bond3)).thenReturn(false); 168 assertTrue(matcher.matches(bond1, bond2)); 169 assertFalse(matcher.matches(bond1, bond3)); 170 } 171 } 172