RingMembershipAtom extends SMARTSAtom { @Override public boolean matches(IAtom atom) { if (ringNumber < 0) return invariants(atom).ringConnectivity() > 0; else if (ringNumber == 0) return invariants(atom).ringConnectivity() == 0; else return ringNumber == invariants(atom).ringNumber(); } RingMembershipAtom(int num, IChemObjectBuilder builder); @Override boolean matches(IAtom atom);  }
@Test public void matches() throws Exception { RingMembershipAtom matcher = new RingMembershipAtom(2, mock(IChemObjectBuilder.class)); IAtom atom = mock(IAtom.class); when(atom.getProperty(SMARTSAtomInvariants.KEY)) .thenReturn( new SMARTSAtomInvariants(mock(IAtomContainer.class), 0, 2, Collections.<Integer> emptySet(), 0, 0, 0, 0)); assertTrue(matcher.matches(atom)); }
@Test public void mismatches() throws Exception { RingMembershipAtom matcher = new RingMembershipAtom(2, mock(IChemObjectBuilder.class)); IAtom atom = mock(IAtom.class); when(atom.getProperty(SMARTSAtomInvariants.KEY)) .thenReturn( new SMARTSAtomInvariants(mock(IAtomContainer.class), 0, 1, Collections.<Integer> emptySet(), 0, 0, 0, 0)); assertFalse(matcher.matches(atom)); }
@Test public void none() throws Exception { RingMembershipAtom matcher = new RingMembershipAtom(0, mock(IChemObjectBuilder.class)); IAtom atom = mock(IAtom.class); when(atom.getProperty(SMARTSAtomInvariants.KEY)) .thenReturn( new SMARTSAtomInvariants(mock(IAtomContainer.class), 0, 0, Collections.<Integer> emptySet(), 0, 0, 0, 0)); assertTrue(matcher.matches(atom)); }
@Test public void any() throws Exception { RingMembershipAtom matcher = new RingMembershipAtom(-1, mock(IChemObjectBuilder.class)); IAtom atom = mock(IAtom.class); when(atom.getProperty(SMARTSAtomInvariants.KEY)) .thenReturn( new SMARTSAtomInvariants(mock(IAtomContainer.class), 0, 5, Collections.<Integer> emptySet(), 2, 0, 0, 0)); assertTrue(matcher.matches(atom)); }