/** * Test whether this expression matches an atom instance. * * @param atom an atom (nullable) * @return the atom matches */ public boolean matches(final IAtom atom) { return atom != null && matches(type, atom, UNKNOWN_STEREO); }
@Test public void testInsaturationF() { Expr expr = new Expr(INSATURATION, 2); IAtom atom = mock(IAtom.class); IBond b1 = mock(IBond.class); IBond b2 = mock(IBond.class); when(b1.getOrder()).thenReturn(IBond.Order.SINGLE); when(b2.getOrder()).thenReturn(IBond.Order.DOUBLE); when(atom.bonds()).thenReturn(Arrays.asList(b1, b2)); assertFalse(expr.matches(atom)); }
@Test public void testValenceNullOrderT() { Expr expr = new Expr(VALENCE, 4); IAtom a1 = mock(IAtom.class); IBond b1 = mock(IBond.class); IBond b2 = mock(IBond.class); when(a1.getImplicitHydrogenCount()).thenReturn(1); when(b1.getOrder()).thenReturn(IBond.Order.DOUBLE); when(b2.getOrder()).thenReturn(null); when(a1.bonds()).thenReturn(Arrays.asList(b1, b2)); assertFalse(expr.matches(a1)); }
@Test public void testUnsaturatedT() { Expr expr = new Expr(UNSATURATED); IAtom atom = mock(IAtom.class); IBond bond = mock(IBond.class); when(bond.getOrder()).thenReturn(IBond.Order.DOUBLE); when(atom.bonds()).thenReturn(Collections.singletonList(bond)); assertTrue(expr.matches(atom)); }
@Test public void testAliphaticElementF() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(ALIPHATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num); when(atom.isAromatic()).thenReturn(true); assertFalse(expr.matches(atom)); } }
@Test public void testAliphaticElementFalse2() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(ALIPHATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num + 1); when(atom.isAromatic()).thenReturn(false); assertFalse(expr.matches(atom)); } }
@Test public void testAromaticElementT() { for (int num = 1; num < 54; ++num) { Expr expr = new Expr(AROMATIC_ELEMENT, num); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(num); when(atom.isAromatic()).thenReturn(true); assertTrue(expr.matches(atom)); } }
@Test public void testTotalDegreeF() { Expr expr = new Expr(TOTAL_DEGREE, 1); IAtom atom = mock(IAtom.class); when(atom.getBondCount()).thenReturn(1); when(atom.getImplicitHydrogenCount()).thenReturn(1); assertFalse(expr.matches(atom)); }
@Test public void testIsotopeT() { Expr expr = new Expr(ISOTOPE, 13); IAtom atom = mock(IAtom.class); when(atom.getMassNumber()).thenReturn(13); assertTrue(expr.matches(atom)); }
@Test public void testHybridisationSp3d4T() { Expr expr = new Expr(HYBRIDISATION_NUMBER, 7); IAtom atom = mock(IAtom.class); when(atom.getHybridization()).thenReturn(IAtomType.Hybridization.SP3D4); assertTrue(expr.matches(atom)); }
@Test public void testBondIsAliphaticT() { Expr expr = new Expr(IS_ALIPHATIC); IBond bond = mock(IBond.class); when(bond.isAromatic()).thenReturn(false); assertTrue(expr.matches(bond)); }
@Test public void testBondOrderNullF() { Expr expr = new Expr(ALIPHATIC_ORDER, 2); IBond bond = mock(IBond.class); when(bond.getOrder()).thenReturn(null); assertFalse(expr.matches(bond)); }
@Test public void testStereoF() { Expr expr = new Expr(STEREOCHEMISTRY, 1); IAtom atom = mock(IAtom.class); assertFalse(expr.matches(atom, 2)); }
@Test public void testBondNotT() { Expr expr = new Expr(NOT, new Expr(TRUE), null); IBond bond = mock(IBond.class); assertFalse(expr.matches(bond)); }
@Test public void testAndTT() { Expr expr = new Expr(AND, new Expr(TRUE), new Expr(TRUE)); IAtom atom = mock(IAtom.class); assertTrue(expr.matches(atom)); }
@Test public void testBondAndFT() { Expr expr = new Expr(AND, new Expr(FALSE), new Expr(TRUE)); IBond bond = mock(IBond.class); assertFalse(expr.matches(bond)); }
@Test public void testOrFF() { Expr expr = new Expr(OR, new Expr(FALSE), new Expr(FALSE)); IAtom atom = mock(IAtom.class); assertFalse(expr.matches(atom)); }
@Test public void testRingSize10() { Expr expr = new Expr(RING_SIZE, 10); IAtomContainer mol = TestMoleculeFactory.makeNaphthalene(); Cycles.markRingAtomsAndBonds(mol); assertTrue(expr.matches(mol.getAtom(0))); }