FromSubsetAtoms extends AbstractFunction<Graph, Graph> { static Atom fromSubset(Atom a, int sum, int deg) { if (!a.subset()) return a; Element e = a.element(); if (a.aromatic() && deg <= sum) sum++; int hCount = a.aromatic() ? Element.implicitAromHydrogenCount(e, sum) : Element.implicitHydrogenCount(e, sum); return new AtomImpl.BracketAtom(-1, a.element(), hCount, 0, 0, a.aromatic()); }  Graph apply(Graph g);  }
@Test public void bracketAtom() { Atom input = new AtomImpl.BracketAtom(Element.Carbon, 1, 0); Atom output = FromSubsetAtoms.fromSubset(input, 0, 0); Assert.assertThat(input, CoreMatchers.is(CoreMatchers .sameInstance(output))); }
@Test public void aliphatic_carbon() { Atom actual = FromSubsetAtoms .fromSubset(AtomImpl.AliphaticSubset.Carbon, 3, 0); Atom expect = new AtomImpl.BracketAtom(Element.Carbon, 1, 0); Assert.assertThat(expect, CoreMatchers.is(actual)); }
@Test public void aromatic_carbon() { Atom actual = FromSubsetAtoms.fromSubset(AtomImpl.AromaticSubset.Carbon, 2, 0); Atom expect = new AtomImpl.BracketAtom(-1, Element.Carbon, 1, 0, 0, true); Assert.assertThat(expect, CoreMatchers.is(actual)); }