static public Object toObject(IDescriptorResult result) throws DescriptorException { if(result instanceof BooleanResult){ boolean booleanValue = ((BooleanResult)result).booleanValue(); return Boolean.valueOf(booleanValue); } else if(result instanceof DoubleResult){ double doubleValue = ((DoubleResult)result).doubleValue(); validateValue(doubleValue); return Double.valueOf(doubleValue); } else if(result instanceof IntegerResult){ int intValue = ((IntegerResult)result).intValue(); return Integer.valueOf(intValue); } throw new DescriptorException(String.valueOf(result)); }
@Test public void testBooleanValue() { Assert.assertTrue(new BooleanResult(true).booleanValue()); Assert.assertFalse(new BooleanResult(false).booleanValue()); }
scalar = new CMLScalar(); scalar.addAttribute(new Attribute("dataType", "xsd:boolean")); scalar.appendChild("" + ((BooleanResult) value).booleanValue()); } else if (value instanceof IntegerArrayResult) { IntegerArrayResult result = (IntegerArrayResult) value;
@Test public void testIsProtonInConjugatedPiSystemDescriptor() throws ClassNotFoundException, CDKException, java.lang.Exception { IAtomicDescriptor descriptor = new IsProtonInConjugatedPiSystemDescriptor(); Object[] params = {new Boolean(true)}; descriptor.setParameters(params); SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("CNC=CC=C"); addExplicitHydrogens(mol); Assert.assertTrue(((BooleanResult) descriptor.calculate(mol.getAtom(13), mol).getValue()).booleanValue()); } }
/** * Checks that the results of the first and the second descriptor results * are identical. * * @param v1 first {@link IDescriptorResult} * @param v2 second {@link IDescriptorResult} * @param errorMessage error message to report when the results are not the same */ private void assertEqualOutput(IDescriptorResult v1, IDescriptorResult v2, String errorMessage) { if (v1 instanceof IntegerResult) { Assert.assertEquals(errorMessage, ((IntegerResult) v1).intValue(), ((IntegerResult) v2).intValue()); } else if (v1 instanceof DoubleResult) { Assert.assertEquals(errorMessage, ((DoubleResult) v1).doubleValue(), ((DoubleResult) v2).doubleValue(), 0.00001); } else if (v1 instanceof BooleanResult) { Assert.assertEquals(errorMessage, ((BooleanResult) v1).booleanValue(), ((BooleanResult) v2).booleanValue()); } else if (v1 instanceof DoubleArrayResult) { DoubleArrayResult da1 = (DoubleArrayResult) v1; DoubleArrayResult da2 = (DoubleArrayResult) v2; for (int i = 0; i < da1.length(); i++) { Assert.assertEquals(errorMessage, da1.get(i), da2.get(i), 0.00001); } } else if (v1 instanceof IntegerArrayResult) { IntegerArrayResult da1 = (IntegerArrayResult) v1; IntegerArrayResult da2 = (IntegerArrayResult) v2; for (int i = 0; i < da1.length(); i++) { Assert.assertEquals(errorMessage, da1.get(i), da2.get(i)); } } }