|
31 | 31 | import org.openscience.cdk.interfaces.AbstractAtomParityTest; |
32 | 32 | import org.openscience.cdk.interfaces.IAtom; |
33 | 33 | import org.openscience.cdk.interfaces.IAtomParity; |
| 34 | +import org.openscience.cdk.interfaces.IChemObjectBuilder; |
| 35 | + |
| 36 | +import java.util.Collections; |
| 37 | +import java.util.HashMap; |
| 38 | +import java.util.Map; |
| 39 | + |
| 40 | +import static org.hamcrest.CoreMatchers.is; |
| 41 | +import static org.hamcrest.CoreMatchers.not; |
| 42 | +import static org.hamcrest.CoreMatchers.sameInstance; |
34 | 43 |
|
35 | 44 | /** |
36 | 45 | * Checks the functionality of the {@link NNAtomParity}. |
@@ -74,4 +83,139 @@ public class NNAtomParityTest extends AbstractAtomParityTest { |
74 | 83 | Assert.assertNotNull(parity); |
75 | 84 | } |
76 | 85 |
|
| 86 | + |
| 87 | + @Test public void testMap_Map_Map() throws CloneNotSupportedException { |
| 88 | + |
| 89 | + IChemObjectBuilder builder = NoNotificationChemObjectBuilder.getInstance(); |
| 90 | + |
| 91 | + IAtom c1 = builder.newInstance(IAtom.class, "C"); |
| 92 | + IAtom o2 = builder.newInstance(IAtom.class, "O"); |
| 93 | + IAtom n3 = builder.newInstance(IAtom.class, "N"); |
| 94 | + IAtom c4 = builder.newInstance(IAtom.class, "C"); |
| 95 | + IAtom h5 = builder.newInstance(IAtom.class, "H"); |
| 96 | + |
| 97 | + // new stereo element |
| 98 | + IAtomParity original = new AtomParity(c1, |
| 99 | + o2,n3,c4,h5, |
| 100 | + 2); |
| 101 | + |
| 102 | + // clone the atoms and place in a map |
| 103 | + Map<IAtom,IAtom> mapping = new HashMap<IAtom,IAtom>(); |
| 104 | + IAtom c1clone = (IAtom) c1.clone(); mapping.put(c1, c1clone); |
| 105 | + IAtom o2clone = (IAtom) o2.clone(); mapping.put(o2, o2clone); |
| 106 | + IAtom n3clone = (IAtom) n3.clone(); mapping.put(n3, n3clone); |
| 107 | + IAtom c4clone = (IAtom) c4.clone(); mapping.put(c4, c4clone); |
| 108 | + IAtom h5clone = (IAtom) h5.clone(); mapping.put(h5, h5clone); |
| 109 | + |
| 110 | + // map the existing element a new element |
| 111 | + IAtomParity mapped = original.map(mapping, Collections.EMPTY_MAP); |
| 112 | + |
| 113 | + Assert.assertThat("mapped chiral atom was the same as the original", |
| 114 | + mapped.getAtom(), is(not(sameInstance(original.getAtom())))); |
| 115 | + Assert.assertThat("mapped chiral atom was not the clone", |
| 116 | + mapped.getAtom(), is(sameInstance(c1clone))); |
| 117 | + |
| 118 | + IAtom[] originalLigands = original.getSurroundingAtoms(); |
| 119 | + IAtom[] mappedLigands = mapped.getSurroundingAtoms(); |
| 120 | + |
| 121 | + Assert.assertThat("first ligand was te same as the original", |
| 122 | + mappedLigands[0], is(not(sameInstance(originalLigands[0])))); |
| 123 | + Assert.assertThat("first mapped ligand was not the clone", |
| 124 | + mappedLigands[0], is(sameInstance(o2clone))); |
| 125 | + Assert.assertThat("second ligand was te same as the original", |
| 126 | + mappedLigands[1], is(not(sameInstance(originalLigands[1])))); |
| 127 | + Assert.assertThat("second mapped ligand was not the clone", |
| 128 | + mappedLigands[1], is(sameInstance(n3clone))); |
| 129 | + Assert.assertThat("third ligand was te same as the original", |
| 130 | + mappedLigands[2], is(not(sameInstance(originalLigands[2])))); |
| 131 | + Assert.assertThat("third mapped ligand was not the clone", |
| 132 | + mappedLigands[2], is(sameInstance(c4clone))); |
| 133 | + Assert.assertThat("forth ligand was te same as the original", |
| 134 | + mappedLigands[3], is(not(sameInstance(originalLigands[3])))); |
| 135 | + Assert.assertThat("forth mapped ligand was not the clone", |
| 136 | + mappedLigands[3], is(sameInstance(h5clone))); |
| 137 | + |
| 138 | + Assert.assertThat("stereo was not mapped", |
| 139 | + mapped.getParity(), is(original.getParity())); |
| 140 | + |
| 141 | + } |
| 142 | + |
| 143 | + @Test(expected = IllegalArgumentException.class) |
| 144 | + public void testMap_Null_Map() throws CloneNotSupportedException { |
| 145 | + |
| 146 | + IChemObjectBuilder builder = NoNotificationChemObjectBuilder.getInstance(); |
| 147 | + |
| 148 | + IAtom c1 = builder.newInstance(IAtom.class, "C"); |
| 149 | + IAtom o2 = builder.newInstance(IAtom.class, "O"); |
| 150 | + IAtom n3 = builder.newInstance(IAtom.class, "N"); |
| 151 | + IAtom c4 = builder.newInstance(IAtom.class, "C"); |
| 152 | + IAtom h5 = builder.newInstance(IAtom.class, "H"); |
| 153 | + |
| 154 | + // new stereo element |
| 155 | + IAtomParity original = new AtomParity(c1, |
| 156 | + o2,n3,c4,h5, |
| 157 | + 2); |
| 158 | + |
| 159 | + |
| 160 | + // map the existing element a new element - should through an IllegalArgumentException |
| 161 | + IAtomParity mapped = original.map(null, Collections.EMPTY_MAP); |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testMap_Map_Map_NullElement() throws CloneNotSupportedException { |
| 167 | + |
| 168 | + IChemObjectBuilder builder = NoNotificationChemObjectBuilder.getInstance(); |
| 169 | + |
| 170 | + IAtom c1 = builder.newInstance(IAtom.class, "C"); |
| 171 | + IAtom o2 = builder.newInstance(IAtom.class, "O"); |
| 172 | + IAtom n3 = builder.newInstance(IAtom.class, "N"); |
| 173 | + IAtom c4 = builder.newInstance(IAtom.class, "C"); |
| 174 | + IAtom h5 = builder.newInstance(IAtom.class, "H"); |
| 175 | + |
| 176 | + // new stereo element |
| 177 | + IAtomParity original = new NNAtomParity(null, |
| 178 | + null, null, null, null, |
| 179 | + 0); |
| 180 | + |
| 181 | + |
| 182 | + // map the existing element a new element |
| 183 | + IAtomParity mapped = original.map(Collections.EMPTY_MAP, Collections.EMPTY_MAP); |
| 184 | + |
| 185 | + Assert.assertNull(mapped.getAtom()); |
| 186 | + Assert.assertNull(mapped.getSurroundingAtoms()[0]); |
| 187 | + Assert.assertNull(mapped.getSurroundingAtoms()[1]); |
| 188 | + Assert.assertNull(mapped.getSurroundingAtoms()[2]); |
| 189 | + Assert.assertNull(mapped.getSurroundingAtoms()[3]); |
| 190 | + |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + public void testMap_Map_Map_EmptyMapping() throws CloneNotSupportedException { |
| 195 | + |
| 196 | + IChemObjectBuilder builder = NoNotificationChemObjectBuilder.getInstance(); |
| 197 | + |
| 198 | + IAtom c1 = builder.newInstance(IAtom.class, "C"); |
| 199 | + IAtom o2 = builder.newInstance(IAtom.class, "O"); |
| 200 | + IAtom n3 = builder.newInstance(IAtom.class, "N"); |
| 201 | + IAtom c4 = builder.newInstance(IAtom.class, "C"); |
| 202 | + IAtom h5 = builder.newInstance(IAtom.class, "H"); |
| 203 | + |
| 204 | + // new stereo element |
| 205 | + IAtomParity original = new NNAtomParity(c1, |
| 206 | + o2,n3,c4,h5, |
| 207 | + 2); |
| 208 | + |
| 209 | + |
| 210 | + // map the existing element a new element - should through an IllegalArgumentException |
| 211 | + IAtomParity mapped = original.map(Collections.EMPTY_MAP, Collections.EMPTY_MAP); |
| 212 | + |
| 213 | + Assert.assertNull(mapped.getAtom()); |
| 214 | + Assert.assertNull(mapped.getSurroundingAtoms()[0]); |
| 215 | + Assert.assertNull(mapped.getSurroundingAtoms()[1]); |
| 216 | + Assert.assertNull(mapped.getSurroundingAtoms()[2]); |
| 217 | + Assert.assertNull(mapped.getSurroundingAtoms()[3]); |
| 218 | + Assert.assertNotNull(mapped.getParity()); |
| 219 | + |
| 220 | + } |
77 | 221 | } |
0 commit comments