DoubleBondElementEncoderFactory implements StereoEncoderFactory { @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { Map<IAtom, Integer> atomToIndex = null; List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(); for (IStereoElement se : container.stereoElements()) { if (se instanceof IDoubleBondStereochemistry) { encoders.add(encoder((IDoubleBondStereochemistry) se, atomToIndex = indexMap(atomToIndex, container), graph)); } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void opposite() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(4); IAtom c1 = mock(IAtom.class); IAtom c2 = mock(IAtom.class); IAtom cl3 = mock(IAtom.class); IAtom cl4 = mock(IAtom.class); when(container.getAtom(0)).thenReturn(c1); when(container.getAtom(1)).thenReturn(c2); when(container.getAtom(2)).thenReturn(cl3); when(container.getAtom(3)).thenReturn(cl4); when(container.atoms()).thenReturn(Arrays.asList(c1, c2, cl3, cl4)); IBond stereoBond = mock(IBond.class); IBond left = mock(IBond.class); IBond right = mock(IBond.class); when(stereoBond.getBegin()).thenReturn(c1); when(stereoBond.getEnd()).thenReturn(c2); when(left.getOther(c1)).thenReturn(cl3); when(right.getOther(c2)).thenReturn(cl4); IDoubleBondStereochemistry dbs = mock(IDoubleBondStereochemistry.class); when(dbs.getStereoBond()).thenReturn(stereoBond); when(dbs.getBonds()).thenReturn(new IBond[]{left, right}); when(dbs.getStereo()).thenReturn(IDoubleBondStereochemistry.Conformation.OPPOSITE); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(dbs)); StereoEncoder encoder = new DoubleBondElementEncoderFactory().create(container, new int[][]{{1, 2}, {0, 3}, {0}, {1}}); assertThat(getGeometricParity(encoder).parity(), is(1)); }
@Test public void together() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(4); IAtom c1 = mock(IAtom.class); IAtom c2 = mock(IAtom.class); IAtom cl3 = mock(IAtom.class); IAtom cl4 = mock(IAtom.class); when(container.getAtom(0)).thenReturn(c1); when(container.getAtom(1)).thenReturn(c2); when(container.getAtom(2)).thenReturn(cl3); when(container.getAtom(3)).thenReturn(cl4); when(container.atoms()).thenReturn(Arrays.asList(c1, c2, cl3, cl4)); IBond stereoBond = mock(IBond.class); IBond left = mock(IBond.class); IBond right = mock(IBond.class); when(stereoBond.getBegin()).thenReturn(c1); when(stereoBond.getEnd()).thenReturn(c2); when(left.getOther(c1)).thenReturn(cl3); when(right.getOther(c2)).thenReturn(cl4); IDoubleBondStereochemistry dbs = mock(IDoubleBondStereochemistry.class); when(dbs.getStereoBond()).thenReturn(stereoBond); when(dbs.getBonds()).thenReturn(new IBond[]{left, right}); when(dbs.getStereo()).thenReturn(IDoubleBondStereochemistry.Conformation.TOGETHER); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(dbs)); StereoEncoder encoder = new DoubleBondElementEncoderFactory().create(container, new int[][]{{1, 2}, {0, 3}, {0}, {1}}); assertThat(getGeometricParity(encoder).parity(), is(-1)); }