BondBasedConfiguration { static Configuration.DoubleBond configurationOf(Graph g, int x, int u, int v, int y) { Edge e = g.edge(u, v); if (e.bond() != Bond.DOUBLE) throw new IllegalArgumentException("atoms u,v are not labelled as a double bond"); Edge e1 = g.edge(u, x); Edge e2 = g.edge(v, y); Bond b1 = e1.bond(u); Bond b2 = e2.bond(v); if (b1 == Bond.IMPLICIT || b1 == Bond.SINGLE) return Configuration.DoubleBond.UNSPECIFIED; if (b2 == Bond.IMPLICIT || b2 == Bond.SINGLE) return Configuration.DoubleBond.UNSPECIFIED; return b1 == b2 ? Configuration.DoubleBond.TOGETHER : Configuration.DoubleBond.OPPOSITE; }    }
@Test(expected = IllegalArgumentException.class) public void nonDoubleBond() throws Exception { Graph g = Graph.fromSmiles("CCCC"); BondBasedConfiguration.configurationOf(g, 0, 1, 2, 3); }
@Test public void opposite1() throws Exception { Graph g = Graph.fromSmiles("F/C=C/F"); assertThat(BondBasedConfiguration.configurationOf(g, 0, 1, 2, 3), is(Configuration.DoubleBond.OPPOSITE)); }
@Test public void opposite2() throws Exception { Graph g = Graph.fromSmiles("F\\C=C\\F"); assertThat(BondBasedConfiguration.configurationOf(g, 0, 1, 2, 3), is(Configuration.DoubleBond.OPPOSITE)); }
@Test public void together1() throws Exception { Graph g = Graph.fromSmiles("F/C=C\\F"); assertThat(BondBasedConfiguration.configurationOf(g, 0, 1, 2, 3), is(Configuration.DoubleBond.TOGETHER)); }
@Test public void together2() throws Exception { Graph g = Graph.fromSmiles("F\\C=C/F"); assertThat(BondBasedConfiguration.configurationOf(g, 0, 1, 2, 3), is(Configuration.DoubleBond.TOGETHER)); }