@Test public void testToString() { assertThat(new Expr(TRUE).toString(), is("TRUE")); assertThat(new Expr(ELEMENT, 8).toString(), is("ELEMENT=8")); assertThat(new Expr(ELEMENT, 8).or(new Expr(DEGREE, 3)).toString(), is("OR(ELEMENT=8,DEGREE=3)")); assertThat(new Expr(ELEMENT, 8).and(new Expr(DEGREE, 3)).toString(), is("AND(ELEMENT=8,DEGREE=3)")); assertThat(new Expr(ELEMENT, 8).negate().toString(), is("NOT(ELEMENT=8)")); assertThat(new Expr(RECURSIVE, null).toString(), is("RECURSIVE(...)")); }
@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 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 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)); }
private boolean parseAtomExpr() { QueryAtom atom = new QueryAtom(mol.getBuilder()); Expr expr = new Expr(Expr.Type.NONE); atom.setExpression(expr); if (!parseExplicitHydrogen(atom, expr) && !parseAtomExpr(atom, expr, '\0')) { error = "Invalid atom expression"; return false; } append(atom); return true; }
@Test public void testHasImplicitHydrogenT() { Expr expr = new Expr(HAS_IMPLICIT_HYDROGEN); IAtom atom = mock(IAtom.class); when(atom.getImplicitHydrogenCount()).thenReturn(1); assertTrue(expr.matches(atom)); when(atom.getImplicitHydrogenCount()).thenReturn(2); assertTrue(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))); }