@Test public void removeFalseOr() { assertThat(new Expr(DEGREE, 2).or(new Expr(FALSE)), is(new Expr(DEGREE, 2))); assertThat(new Expr(DEGREE, 2).or(new Expr(TRUE)), is(new Expr(DEGREE, 2))); assertThat(new Expr(FALSE).or(new Expr(DEGREE, 2)), is(new Expr(DEGREE, 2))); assertThat(new Expr(TRUE).or(new Expr(DEGREE, 2)), is(new Expr(DEGREE, 2))); }
case OR: if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2))) || e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1)))) bondType = 5; else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.IS_AROMATIC))) || e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1)))) bondType = 6; else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.IS_AROMATIC))) || e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2)))) bondType = 6; break;
@Test public void singleOrDouble() { Expr expr = new Expr(ALIPHATIC_ORDER, 1) .or(new Expr(ALIPHATIC_ORDER, 2)); assertThat(Smarts.generateBond(expr), is("-,=")); }
case OR: if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2))) || e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1)))) { bondType = 5; else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 1).or(new Expr(Expr.Type.IS_AROMATIC))) || e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 1)))) { bondType = 6; else if (e.equals(new Expr(Expr.Type.ALIPHATIC_ORDER, 2).or(new Expr(Expr.Type.IS_AROMATIC))) || e.equals(new Expr(Expr.Type.IS_AROMATIC).or(new Expr(Expr.Type.ALIPHATIC_ORDER, 2)))) { bondType = 6;
private boolean parseRange(Expr expr) { if (next() != '{') return false; int lo = nextUnsignedInt(); if (next() != '-') return false; int hi = nextUnsignedInt(); Expr.Type type = expr.type(); // adjusted types switch (type) { case HAS_IMPLICIT_HYDROGEN: type = IMPL_H_COUNT; break; } expr.setPrimitive(type, lo); for (int i = lo + 1; i <= hi; i++) expr.or(new Expr(type, i)); return next() == '}'; }
/** * Utility, combine this expression with another, using disjunction. * The expression will match if either conditions is met. * @param expr the other expression * @return self for chaining */ public Expr or(Expr expr) { if (type == Type.TRUE || type == Type.FALSE || type == NONE) { set(expr); } else if (expr.type != Type.TRUE && expr.type != Type.FALSE && expr.type != Type.NONE) { if (type.isLogical() && !expr.type.isLogical()) { if (type == OR) right.or(expr); else setLogical(Type.OR, expr, new Expr(this)); } else setLogical(Type.OR, new Expr(this), expr); } return this; }
@Test public void useLowPrecedenceAnd() { Expr expr = new Expr(ELEMENT, 8).and( new Expr(DEGREE, 2).or( new Expr(DEGREE, 1))); assertThat(Smarts.generateAtom(expr), is("[#8;D2,D]")); }
@Test public void singleOrDoubleInRing() { Expr expr = new Expr(IS_IN_RING) .and(new Expr(ALIPHATIC_ORDER, 1) .or(new Expr(ALIPHATIC_ORDER, 2))); assertThat(Smarts.generateBond(expr), is("@;-,=")); }
@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 testBondNotStereo3() { Expr expr = new Expr(NOT, new Expr(STEREOCHEMISTRY, 1).or(new Expr(STEREOCHEMISTRY, 0)), null); IBond bond = mock(IBond.class); assertTrue(expr.matches(bond)); assertTrue(expr.matches(bond, 2)); assertFalse(expr.matches(bond, 1)); }
@Test public void testNotStereo3() { Expr expr = new Expr(NOT, new Expr(STEREOCHEMISTRY, 1).or(new Expr(STEREOCHEMISTRY, 0)), null); IAtom atom = mock(IAtom.class); assertTrue(expr.matches(atom)); assertTrue(expr.matches(atom, 2)); assertFalse(expr.matches(atom, 1)); }