ToleranceRangeRule implements IRule { @Override public double validate(IMolecularFormula formula) throws CDKException { logger.info("Start validation of ", formula); double totalExactMass = MolecularFormulaManipulator.getTotalExactMass(formula); if (Math.abs(totalExactMass - mass) > tolerance) return 0.0; else return 1.0; } ToleranceRangeRule(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override double validate(IMolecularFormula formula);  }
@Test public void testDefaultValidFalse() throws Exception { IRule rule = new ToleranceRangeRule(); IMolecularFormula formula = new MolecularFormula(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); carb.setExactMass(12.00); IIsotope cl = builder.newInstance(IIsotope.class, "Cl"); cl.setExactMass(34.96885268); formula.addIsotope(carb); formula.addIsotope(cl); Assert.assertEquals(0.0, rule.validate(formula), 0.0001); }