Skip to content
Browse files

Factored out a method to test whether to descriptor calculations give…

… the same results

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
1 parent 4d7c6b5 commit 861c30409a74d77613d7acbb372441a3b6c29e12 @egonw egonw committed
Showing with 35 additions and 43 deletions.
  1. +35 −43 src/test/org/openscience/cdk/qsar/descriptors/molecular/MolecularDescriptorTest.java
View
78 src/test/org/openscience/cdk/qsar/descriptors/molecular/MolecularDescriptorTest.java
@@ -223,25 +223,7 @@ public void testTakeIntoAccountImplicitHydrogens() {
IDescriptorResult v2 = descriptor.calculate(methane2).getValue();
String errorMessage = "("+descriptor.getClass().toString()+") The descriptor does not give the same results depending on whether hydrogens are implicit or explicit.";
- 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));
- }
- }
+ assertEqualOutput(v1, v2, errorMessage);
}
@Test
@@ -289,23 +271,51 @@ public void testTakeIntoAccountImplicitHydrogensInEthane() {
IDescriptorResult v2 = descriptor.calculate(ethane2).getValue();
String errorMessage = "(" + descriptor.getClass().toString() + ") The descriptor does not give the same results depending on whether hydrogens are implicit or explicit.";
+ assertEqualOutput(v1, v2, errorMessage);
+ }
+
+ /**
+ * 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());
+ 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);
+ 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());
+ 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);
+ 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));
+ Assert.assertEquals(errorMessage,
+ da1.get(i), da2.get(i)
+ );
}
}
}
@@ -333,25 +343,7 @@ public void testTakeIntoAccountImplicitHydrogensInEthane() {
IDescriptorResult v2 = descriptor.calculate(ethane2).getValue();
String errorMessage = "("+descriptor.getClass().toString()+") The descriptor does not give the same results depending on whether bond order or atom type are considered.";
- 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));
- }
- }
+ assertEqualOutput(v1, v2, errorMessage);
}
private IMolecule someoneBringMeSomeWater(IChemObjectBuilder builder) throws Exception {

0 comments on commit 861c304

Please sign in to comment.
Something went wrong with that request. Please try again.