be more restrictive on ignored exceptions for the test
added a long to double conversion to also test the getN() methods git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@611628 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cc13556bb6
commit
d085445d68
|
@ -20,6 +20,7 @@ package org.apache.commons.math.stat.data;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -113,30 +114,48 @@ public abstract class CertifiedDataAbstractTest extends TestCase {
|
||||||
|
|
||||||
public void testCertifiedValues() {
|
public void testCertifiedValues() {
|
||||||
Iterator iter = certifiedValues.keySet().iterator();
|
Iterator iter = certifiedValues.keySet().iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
String name = iter.next().toString();
|
String name = iter.next().toString();
|
||||||
Double expectedValue = (Double)certifiedValues.get(name);
|
Double expectedValue = (Double)certifiedValues.get(name);
|
||||||
try {
|
|
||||||
Double summariesValue = (Double)this.getProperty(summaries, name);
|
Double summariesValue = getProperty(summaries, name);
|
||||||
|
if (summariesValue != null) {
|
||||||
TestUtils.assertEquals("summary value for " + name + " is incorrect.",
|
TestUtils.assertEquals("summary value for " + name + " is incorrect.",
|
||||||
summariesValue.doubleValue(), expectedValue.doubleValue(), getMaximumAbsoluteError());
|
summariesValue.doubleValue(), expectedValue.doubleValue(),
|
||||||
} catch (Exception ex) {
|
getMaximumAbsoluteError());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
Double descriptivesValue = getProperty(descriptives, name);
|
||||||
Double descriptivesValue = (Double)this.getProperty(descriptives, name);
|
if (descriptivesValue != null) {
|
||||||
TestUtils.assertEquals("descriptive value for " + name + " is incorrect.",
|
TestUtils.assertEquals("descriptive value for " + name + " is incorrect.",
|
||||||
descriptivesValue.doubleValue(), expectedValue.doubleValue(), getMaximumAbsoluteError());
|
descriptivesValue.doubleValue(), expectedValue.doubleValue(),
|
||||||
} catch (Exception ex) {
|
getMaximumAbsoluteError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Object getProperty(Object bean, String name) throws Exception{
|
protected Double getProperty(Object bean, String name) {
|
||||||
|
try {
|
||||||
// Get the value of prop
|
// Get the value of prop
|
||||||
String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
|
String prop = "get" + name.substring(0,1).toUpperCase() + name.substring(1);
|
||||||
Method meth = bean.getClass().getMethod(prop, new Class[0]);
|
Method meth = bean.getClass().getMethod(prop, new Class[0]);
|
||||||
return meth.invoke(bean, new Object[0]);
|
Object property = meth.invoke(bean, new Object[0]);
|
||||||
|
if (meth.getReturnType().equals(Double.TYPE)) {
|
||||||
|
return (Double) property;
|
||||||
|
} else if (meth.getReturnType().equals(Long.TYPE)) {
|
||||||
|
return new Double(((Long) property).doubleValue());
|
||||||
|
} else {
|
||||||
|
fail("wrong type: " + meth.getReturnType().getName());
|
||||||
|
}
|
||||||
|
} catch (NoSuchMethodException nsme) {
|
||||||
|
// ignored
|
||||||
|
} catch (InvocationTargetException ite) {
|
||||||
|
fail(ite.getMessage());
|
||||||
|
} catch (IllegalAccessException iae) {
|
||||||
|
fail(iae.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue