ImplicitToExplicit extends AbstractFunction<Graph,Graph> { public Graph apply(final Graph g) { Graph h = new Graph(g.order()); for (int u = 0; u < g.order(); u++) { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } for (int u = 0; u < g.order(); u++) { for (final Edge e : g.edges(u)) { if (e.other(u) > u) h.addEdge(toExplicitEdge(g, e)); } } return h; }  Graph apply(final Graph g);  }
@Test public void kekuleBenzene() throws Exception { Graph g = new Graph(6); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addEdge(new Edge(0, 1, IMPLICIT)); g.addEdge(new Edge(1, 2, DOUBLE)); g.addEdge(new Edge(2, 3, IMPLICIT)); g.addEdge(new Edge(3, 4, DOUBLE)); g.addEdge(new Edge(4, 5, IMPLICIT)); g.addEdge(new Edge(5, 0, DOUBLE)); Graph h = new ImplicitToExplicit().apply(g); Assert.assertThat(g, CoreMatchers.is(CoreMatchers.not(CoreMatchers .sameInstance(h)))); Assert.assertThat(h.edges(0), CoreMatchers .hasItems(new Edge(0, 1, SINGLE), new Edge(0, 5, DOUBLE))); Assert.assertThat(h.edges(1), CoreMatchers .hasItems(new Edge(1, 0, SINGLE), new Edge(1, 2, DOUBLE))); Assert.assertThat(h.edges(2), CoreMatchers .hasItems(new Edge(2, 1, DOUBLE), new Edge(2, 3, SINGLE))); Assert.assertThat(h.edges(3), CoreMatchers .hasItems(new Edge(3, 2, SINGLE), new Edge(3, 4, DOUBLE))); Assert.assertThat(h.edges(4), CoreMatchers .hasItems(new Edge(4, 3, DOUBLE), new Edge(4, 5, SINGLE))); Assert.assertThat(h.edges(5), CoreMatchers .hasItems(new Edge(5, 0, DOUBLE), new Edge(5, 4, SINGLE))); }
@Test public void cycloHexane() throws Exception { Graph g = new Graph(6); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addAtom(AtomImpl.AliphaticSubset.Carbon); g.addEdge(new Edge(0, 1, IMPLICIT)); g.addEdge(new Edge(1, 2, IMPLICIT)); g.addEdge(new Edge(2, 3, IMPLICIT)); g.addEdge(new Edge(3, 4, IMPLICIT)); g.addEdge(new Edge(4, 5, IMPLICIT)); g.addEdge(new Edge(5, 0, IMPLICIT)); Graph h = new ImplicitToExplicit().apply(g); Assert.assertThat(g, CoreMatchers.is(CoreMatchers.not(CoreMatchers .sameInstance(h)))); for (int u = 0; u < h.order(); u++) { for (Edge e : h.edges(u)) { Assert.assertThat(e.bond(), CoreMatchers.is(SINGLE)); } } }
@Test public void aromaticBenzene() throws Exception { Graph g = new Graph(6); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addAtom(AtomImpl.AromaticSubset.Carbon); g.addEdge(new Edge(0, 1, IMPLICIT)); g.addEdge(new Edge(1, 2, IMPLICIT)); g.addEdge(new Edge(2, 3, IMPLICIT)); g.addEdge(new Edge(3, 4, IMPLICIT)); g.addEdge(new Edge(4, 5, IMPLICIT)); g.addEdge(new Edge(5, 0, IMPLICIT)); Graph h = new ImplicitToExplicit().apply(g); Assert.assertThat(g, CoreMatchers.is(CoreMatchers.not(CoreMatchers .sameInstance(h)))); for (int u = 0; u < h.order(); u++) { for (Edge e : h.edges(u)) { Assert.assertThat(e.bond(), CoreMatchers.is(AROMATIC)); } } }