rapodaca / mx forked from metamolecular/mx
- Source
- Commits
- Network (2)
- Issues (2)
- Downloads (9)
- Wiki (1)
- Graphs
-
Tree:
36d044b
commit 36d044b6ca2f5ec8cc71db25545fa2a3ca368458
tree 4379ea24065ed71b998aab9f9e899df5b7139672
parent 265e25aff96152296538b04f63a9afebac8bedd0
tree 4379ea24065ed71b998aab9f9e899df5b7139672
parent 265e25aff96152296538b04f63a9afebac8bedd0
| 69832817 » | rapodaca | 2009-06-27 | 1 | /* | |
| 2 | * MX Cheminformatics Tools for Java | ||||
| 3 | * | ||||
| 4 | * Copyright (c) 2007-2009 Metamolecular, LLC | ||||
| 5 | * | ||||
| 6 | * http://metamolecular.com | ||||
| 7 | * | ||||
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| 9 | * of this software and associated documentation files (the "Software"), to deal | ||||
| 10 | * in the Software without restriction, including without limitation the rights | ||||
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| 12 | * copies of the Software, and to permit persons to whom the Software is | ||||
| 13 | * furnished to do so, subject to the following conditions: | ||||
| 14 | * | ||||
| 15 | * The above copyright notice and this permission notice shall be included in | ||||
| 16 | * all copies or substantial portions of the Software. | ||||
| 17 | * | ||||
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
| 24 | * THE SOFTWARE. | ||||
| 25 | */ | ||||
| 26 | package com.metamolecular.mx.test; | ||||
| 27 | |||||
| 28 | import com.metamolecular.mx.model.Atom; | ||||
| 29 | import com.metamolecular.mx.model.Bond; | ||||
| 30 | import com.metamolecular.mx.walk.Step; | ||||
| 31 | import com.metamolecular.mx.walk.DefaultWalker; | ||||
| 32 | import com.metamolecular.mx.walk.Reporter; | ||||
| 33 | import java.util.List; | ||||
| 34 | import junit.framework.TestCase; | ||||
| 35 | import static org.mockito.Mockito.*; | ||||
| 36 | |||||
| 37 | /** | ||||
| 38 | * @author Richard L. Apodaca <rapodaca at metamolecular.com> | ||||
| 39 | */ | ||||
| 40 | public class DefaultWalkerTest extends TestCase | ||||
| 41 | { | ||||
| 42 | private DefaultWalker walker; | ||||
| 43 | private Reporter reporter; | ||||
| 44 | private Step step; | ||||
| 45 | private List path; | ||||
| 46 | private Atom atom; | ||||
| 47 | private Bond bond; | ||||
| 48 | |||||
| 49 | @Override | ||||
| 50 | protected void setUp() throws Exception | ||||
| 51 | { | ||||
| 52 | walker = new DefaultWalker(); | ||||
| 53 | reporter = mock(Reporter.class); | ||||
| 54 | step = mock(Step.class); | ||||
| 55 | path = mock(List.class); | ||||
| 56 | atom = mock(Atom.class); | ||||
| 57 | bond = mock(Bond.class); | ||||
| 58 | |||||
| 59 | when(step.getPath()).thenReturn(path); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 60 | when(step.getAtom()).thenReturn(atom); | |
| 69832817 » | rapodaca | 2009-06-27 | 61 | } | |
| 62 | |||||
| 63 | public void testItSetsMaximumDepth() | ||||
| 64 | { | ||||
| 65 | walker.setMaximumDepth(5); | ||||
| 66 | |||||
| 67 | assertEquals(5, walker.getMaximumDepth()); | ||||
| 68 | } | ||||
| 69 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 70 | public void testItDoesntRequestNextBondWhenMaximumDepthReached() | |
| 69832817 » | rapodaca | 2009-06-27 | 71 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 72 | walker.setMaximumDepth(2); | |
| 73 | when(path.size()).thenReturn(2); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 74 | doStep(); | |
| 36d044b6 » | rapodaca | 2009-06-29 | 75 | verify(step, never()).nextBond(); | |
| 69832817 » | rapodaca | 2009-06-27 | 76 | } | |
| 77 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 78 | public void testItRequestsNextBondWhenMaximumDepthNotReached() | |
| 69832817 » | rapodaca | 2009-06-27 | 79 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 80 | Step branch1 = mock(Step.class); | |
| 81 | |||||
| 82 | walker.setMaximumDepth(2); | ||||
| 83 | when(path.size()).thenReturn(1); | ||||
| 84 | when(step.hasNextBond()).thenReturn(true, false); | ||||
| 409af281 » | rapodaca | 2009-06-27 | 85 | when(step.nextBond()).thenReturn(bond); | |
| 36d044b6 » | rapodaca | 2009-06-29 | 86 | when(step.nextStep(bond)).thenReturn(branch1); | |
| 69832817 » | rapodaca | 2009-06-27 | 87 | doStep(); | |
| 36d044b6 » | rapodaca | 2009-06-29 | 88 | verify(step, times(1)).nextBond(); | |
| 69832817 » | rapodaca | 2009-06-27 | 89 | } | |
| 90 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 91 | public void testItRequestsNextBondWhenMaximumDepthNotSet() | |
| 69832817 » | rapodaca | 2009-06-27 | 92 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 93 | Step branch1 = mock(Step.class); | |
| 94 | |||||
| 95 | walker.setMaximumDepth(0); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 96 | ||
| 36d044b6 » | rapodaca | 2009-06-29 | 97 | when(path.size()).thenReturn(2); | |
| 98 | when(step.hasNextBond()).thenReturn(true, false); | ||||
| 409af281 » | rapodaca | 2009-06-27 | 99 | when(step.nextBond()).thenReturn(bond); | |
| 36d044b6 » | rapodaca | 2009-06-29 | 100 | when(branch1.getAtom()).thenReturn(atom); | |
| 101 | when(step.nextStep(bond)).thenReturn(branch1); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 102 | ||
| 36d044b6 » | rapodaca | 2009-06-29 | 103 | doStep(); | |
| 104 | verify(step, times(1)).nextBond(); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 105 | } | |
| 106 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 107 | public void testItDoesntCheckPathDepthWhenNotSet() | |
| 69832817 » | rapodaca | 2009-06-27 | 108 | { | |
| 109 | doStep(); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 110 | verify(path, never()).size(); | |
| 69832817 » | rapodaca | 2009-06-27 | 111 | } | |
| 112 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 113 | public void testItReportsAtomWhenNextBondUnavailable() | |
| 69832817 » | rapodaca | 2009-06-27 | 114 | { | |
| 115 | doStep(); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 116 | verify(reporter, times(1)).atomFound(atom); | |
| 69832817 » | rapodaca | 2009-06-27 | 117 | } | |
| 118 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 119 | public void testItReporstNoBranchStartWhenStepHasOneBond() | |
| 69832817 » | rapodaca | 2009-06-27 | 120 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 121 | Step branch1 = mock(Step.class); | |
| 69832817 » | rapodaca | 2009-06-27 | 122 | ||
| 36d044b6 » | rapodaca | 2009-06-29 | 123 | when(step.hasNextBond()).thenReturn(true, false); | |
| 124 | when(step.nextBond()).thenReturn(bond); | ||||
| 125 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 126 | when(step.nextStep(any(Bond.class))).thenReturn(branch1); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 127 | ||
| 128 | doStep(); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 129 | verify(reporter, times(0)).branchStart(); | |
| 69832817 » | rapodaca | 2009-06-27 | 130 | } | |
| 131 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 132 | public void testItReportsNoBranchEndWhenStepHasOneBond() | |
| 22907ddc » | rapodaca | 2009-06-27 | 133 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 134 | Step branch1 = mock(Step.class); | |
| 22907ddc » | rapodaca | 2009-06-27 | 135 | ||
| 36d044b6 » | rapodaca | 2009-06-29 | 136 | when(step.hasNextBond()).thenReturn(true, false); | |
| 137 | when(step.nextBond()).thenReturn(bond); | ||||
| 138 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 139 | when(step.nextStep(any(Bond.class))).thenReturn(branch1); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 140 | ||
| 141 | doStep(); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 142 | verify(reporter, times(0)).branchEnd(); | |
| 69832817 » | rapodaca | 2009-06-27 | 143 | } | |
| 144 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 145 | public void testItReportsTwoBranchStartsWhenStepHasThreeBonds() | |
| 69832817 » | rapodaca | 2009-06-27 | 146 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 147 | when(step.hasNextBond()).thenReturn(true, true, true, false); | |
| 409af281 » | rapodaca | 2009-06-27 | 148 | when(step.nextBond()).thenReturn(bond); | |
| 69832817 » | rapodaca | 2009-06-27 | 149 | ||
| 36d044b6 » | rapodaca | 2009-06-29 | 150 | Step branch1 = mock(Step.class); | |
| 151 | Step branch2 = mock(Step.class); | ||||
| 152 | Step branch3 = mock(Step.class); | ||||
| 153 | |||||
| 154 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 155 | when(branch2.getAtom()).thenReturn(atom); | ||||
| 156 | when(branch3.getAtom()).thenReturn(atom); | ||||
| 157 | |||||
| 158 | when(step.nextStep(any(Bond.class))).thenReturn(branch1, branch2, branch3); | ||||
| 159 | |||||
| 160 | doStep(); | ||||
| 161 | verify(reporter, times(2)).branchStart(); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 162 | } | |
| 163 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 164 | public void testItReportsTwoBranchEndsWhenStepHasThreeBonds() | |
| 69832817 » | rapodaca | 2009-06-27 | 165 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 166 | when(step.hasNextBond()).thenReturn(true, true, true, false); | |
| 167 | when(step.nextBond()).thenReturn(bond); | ||||
| 168 | |||||
| 169 | Step branch1 = mock(Step.class); | ||||
| 170 | Step branch2 = mock(Step.class); | ||||
| 171 | Step branch3 = mock(Step.class); | ||||
| 172 | |||||
| 173 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 174 | when(branch2.getAtom()).thenReturn(atom); | ||||
| 175 | when(branch3.getAtom()).thenReturn(atom); | ||||
| 176 | |||||
| 177 | when(step.nextStep(any(Bond.class))).thenReturn(branch1, branch2, branch3); | ||||
| 178 | |||||
| 179 | doStep(); | ||||
| 180 | verify(reporter, times(2)).branchEnd(); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 181 | } | |
| 182 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 183 | public void testItReportsRingClosureWhenStepNextBondClosesRing() | |
| 69832817 » | rapodaca | 2009-06-27 | 184 | { | |
| 409af281 » | rapodaca | 2009-06-27 | 185 | when(step.hasNextBond()).thenReturn(true, false); | |
| 186 | when(step.nextBond()).thenReturn(bond); | ||||
| 36d044b6 » | rapodaca | 2009-06-29 | 187 | ||
| 188 | Step branch1 = mock(Step.class); | ||||
| 189 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 190 | when(step.nextStep(bond)).thenReturn(branch1); | ||||
| 191 | when(step.closesRingWith(bond)).thenReturn(true); | ||||
| 192 | |||||
| 193 | doStep(); | ||||
| 194 | verify(reporter, times(1)).ringClosed(bond); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 195 | } | |
| 196 | |||||
| 36d044b6 » | rapodaca | 2009-06-29 | 197 | public void testItDoesntReportRingClosureWhenStepNextBondDoesntCloseRing() | |
| 69832817 » | rapodaca | 2009-06-27 | 198 | { | |
| 36d044b6 » | rapodaca | 2009-06-29 | 199 | when(step.hasNextBond()).thenReturn(true, false); | |
| 409af281 » | rapodaca | 2009-06-27 | 200 | when(step.nextBond()).thenReturn(bond); | |
| 36d044b6 » | rapodaca | 2009-06-29 | 201 | ||
| 202 | Step branch1 = mock(Step.class); | ||||
| 203 | when(branch1.getAtom()).thenReturn(atom); | ||||
| 204 | when(step.nextStep(bond)).thenReturn(branch1); | ||||
| 205 | when(step.closesRingWith(bond)).thenReturn(false); | ||||
| 206 | |||||
| 207 | doStep(); | ||||
| 208 | verify(reporter, never()).ringClosed(bond); | ||||
| 69832817 » | rapodaca | 2009-06-27 | 209 | } | |
| 210 | |||||
| 211 | private void doStep() | ||||
| 212 | { | ||||
| 213 | walker.step(step, reporter); | ||||
| 214 | } | ||||
| 215 | } | ||||
