ChargeRule implements IRule { @Override public double validate(IMolecularFormula formula) throws CDKException { logger.info("Start validation of ", formula); if (formula.getCharge() == null) { return 0.0; } else if (formula.getCharge() == charge) { return 1.0; } else { return 0.0; } } ChargeRule(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override double validate(IMolecularFormula formula);  }
@Test public void testDefaultValidFalse() throws ClassNotFoundException, CDKException, Exception { IRule rule = new ChargeRule(); IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C"), 2); formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 200); formula.setCharge(1); Assert.assertEquals(0.0, rule.validate(formula), 0.0001); }
@Test public void testDefaultValidTrue() throws ClassNotFoundException, CDKException, Exception { IRule rule = new ChargeRule(); IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C"), 2); formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 6); formula.setCharge(0); Assert.assertEquals(1.0, rule.validate(formula), 0.0001); }