Obtained from:
Submitted by:	Brent Worden 
Reviewed by:	Mark Diggory


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-09-27 04:13:34 +00:00
parent 609917a77c
commit d8931052e4
28 changed files with 1381 additions and 292 deletions

View File

@ -2,7 +2,7 @@
<!-- <!--
build.xml generated by maven from project.xml version 0.1-dev build.xml generated by maven from project.xml version 0.1-dev
on date September 17 2003, time 1526 on date September 27 2003, time 0007
--> -->
<project default="jar" name="commons-math" basedir="."> <project default="jar" name="commons-math" basedir=".">
@ -149,14 +149,16 @@
</javadoc> </javadoc>
</target> </target>
<target name="get-deps" unless="noget" depends="init"> <target name="get-deps" unless="noget" depends="init">
<get dest="${libdir}/commons-beanutils-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-SNAPSHOT.jar"> <get dest="${libdir}/commons-beanutils-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-1.5.jar">
</get> </get>
<get dest="${libdir}/commons-collections-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-collections/jars/commons-collections-SNAPSHOT.jar"> <get dest="${libdir}/commons-collections-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-collections/jars/commons-collections-SNAPSHOT.jar">
</get> </get>
<get dest="${libdir}/commons-discovery-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-discovery/jars/commons-discovery-SNAPSHOT.jar"> <get dest="${libdir}/commons-lang-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-lang/jars/commons-lang-SNAPSHOT.jar">
</get> </get>
<get dest="${libdir}/commons-logging-1.0.3.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.3.jar"> <get dest="${libdir}/commons-logging-1.0.3.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.3.jar">
</get> </get>
<get dest="${libdir}/commons-discovery-SNAPSHOT.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-discovery/jars/commons-discovery-SNAPSHOT.jar">
</get>
<get dest="${libdir}/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar"> <get dest="${libdir}/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar">
</get> </get>
<get dest="${libdir}/ant-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar"> <get dest="${libdir}/ant-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar">

View File

@ -1,134 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1.25 $ $Date: 2003/09/26 19:30:32 $ --> <!-- $Revision: 1.26 $ $Date: 2003/09/27 04:13:34 $ -->
<project> <project>
<extend>../../jakarta-commons/project.xml</extend> <extend>../../jakarta-commons/project.xml</extend>
<name>Math</name> <name>Math</name>
<id>commons-math</id> <id>commons-math</id>
<currentVersion>0.1-dev</currentVersion> <currentVersion>0.1-dev</currentVersion>
<inceptionYear>2003</inceptionYear> <inceptionYear>2003</inceptionYear>
<logo/> <logo/>
<shortDescription>A library of lightweight, self-contained mathematics and <shortDescription>
statistics components.</shortDescription> A library of lightweight, self-contained mathematics and statistics components.
<description>The Math project is a library of lightweight, self-contained </shortDescription>
mathematics and statistics components addressing the most common practical <description>
problems not immediately available in the Java programming language or The Math project is a library of lightweight, self-contained mathematics and statistics components addressing the most common practical problems not immediately available in the Java programming language or commons-lang.
commons-lang.</description> </description>
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/math/</siteDirectory> <siteDirectory>/www/jakarta.apache.org/commons/sandbox/math/</siteDirectory>
<versions> <versions>
<version> <version>
<id>0.1-dev</id> <id>0.1-dev</id>
<name>0.1-dev</name> <name>0.1-dev</name>
</version> </version>
</versions> </versions>
<developers>
<developer> <developers>
<name>Robert Burrell Donkin</name> <developer>
<id>rdonkin</id> <name>Robert Burrell Donkin</name>
<email>rdonkin@apache.org</email> <id>rdonkin</id>
</developer> <email>rdonkin@apache.org</email>
<developer> </developer>
<name>Tim OBrien</name> <developer>
<id>tobrien</id> <name>Tim OBrien</name>
<email>tobrien@apache.org</email> <id>tobrien</id>
</developer> <email>tobrien@apache.org</email>
<developer> </developer>
<name>Mark R. Diggory</name> <developer>
<id>mdiggory</id> <name>Mark R. Diggory</name>
<email>mdiggory@apache.org</email> <id>mdiggory</id>
</developer> <email>mdiggory@apache.org</email>
<developer> </developer>
<name>J.Pietschmann</name> </developers>
<id>pietsch</id>
<email>pietsch@apache.org</email> <contributors>
<email>j3322ptm@yahoo.de</email> <contributor>
</developer> <name>Phil Steitz</name>
</developers> <email>phil@steitz.com</email>
<contributors> <roles>
<contributor> <role>proposal author</role>
<name>Phil Steitz</name> <role>initial contributor</role>
<email>phil@steitz.com</email> </roles>
<roles> </contributor>
<role>proposal author</role> <contributor>
<role>initial contributor</role> <name>Brent Worden</name>
</roles> <email>brent@worden.org</email>
</contributor> </contributor>
<contributor> <contributor>
<name>Brent Worden</name> <name>Albert Davidson Chou</name>
<email>brent@worden.org</email> <email>hotfusionman@yahoo.com</email>
</contributor> </contributor>
<contributor> <contributor>
<name>Albert Davidson Chou</name> <name>J.Pietschmann</name>
<email>hotfusionman@yahoo.com</email> <email>j3322ptm@yahoo.de</email>
</contributor> </contributor>
</contributors> </contributors>
<dependencies>
<dependency> <dependencies>
<id>commons-beanutils</id> <dependency>
<version>SNAPSHOT</version> <id>commons-beanutils</id>
</dependency> <version>1.5</version>
<dependency> </dependency>
<id>commons-collections</id> <dependency>
<version>SNAPSHOT</version> <id>commons-collections</id>
</dependency> <version>SNAPSHOT</version>
<dependency> </dependency>
<id>commons-discovery</id> <dependency>
<version>SNAPSHOT</version> <id>commons-lang</id>
</dependency> <version>SNAPSHOT</version>
<dependency> </dependency>
<id>commons-logging</id> <dependency>
<version>1.0.3</version> <id>commons-logging</id>
</dependency> <version>1.0.3</version>
</dependencies> </dependency>
<issueTrackingUrl>http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&amp; <dependency>
bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;email1=&amp; <id>commons-discovery</id>
emailtype1=substring&amp;emailassigned_to1=1&amp;email2=&amp; <version>SNAPSHOT</version>
emailtype2=substring&amp;emailreporter2=1&amp;bugidtype=include&amp;bug_id=&amp; </dependency>
changedin=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp; </dependencies>
product=Commons&amp;component=Sandbox&amp;short_desc=&amp;
short_desc_type=allwordssubstr&amp;long_desc=&amp; <issueTrackingUrl>http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;email1=&amp;emailtype1=substring&amp;emailassigned_to1=1&amp;email2=&amp;emailtype2=substring&amp;emailreporter2=1&amp;bugidtype=include&amp;bug_id=&amp;changedin=&amp;votes=&amp;chfieldfrom=&amp;chfieldto=Now&amp;chfieldvalue=&amp;product=Commons&amp;component=Sandbox&amp;short_desc=&amp;short_desc_type=allwordssubstr&amp;long_desc=&amp;long_desc_type=allwordssubstr&amp;bug_file_loc=&amp;bug_file_loc_type=allwordssubstr&amp;keywords=&amp;keywords_type=anywords&amp;field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=&amp;cmdtype=doit&amp;order=%27Importance%27</issueTrackingUrl>
long_desc_type=allwordssubstr&amp;bug_file_loc=&amp;
bug_file_loc_type=allwordssubstr&amp;keywords=&amp;keywords_type=anywords&amp; <repository>
field0-0-0=noop&amp;type0-0-0=noop&amp;value0-0-0=&amp;cmdtype=doit&amp; <connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons-sandbox/${pom.artifactId.substring(8)}</connection>
order=%27Importance%27</issueTrackingUrl> <url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/${pom.artifactId.substring(8)}/</url>
<repository> </repository>
<connection>
scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons-sandbox/${pom.artifactId.substring(8)}</connection> <build>
<url> <unitTest>
http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/${pom.artifactId.substring(8)}/</url> <includes>
</repository> <include>**/*Test.java</include>
<build> </includes>
<unitTest> <excludes>
<includes> <exclude>**/*AbstractTest.java</exclude>
<include>**/*Test.java</include> </excludes>
</includes> <resources>
<excludes> <resource>
<exclude>**/*AbstractTest.java</exclude> <directory>${pom.build.unitTestSourceDirectory}</directory>
</excludes> <includes>
<resources> <include>**/*.xml</include>
<resource> <include>**/*.txt</include>
<directory>${pom.build.unitTestSourceDirectory}</directory> </includes>
<includes> </resource>
<include>**/*.xml</include> </resources>
<include>**/*.txt</include> </unitTest>
</includes> </build>
</resource>
</resources> <reports>
</unitTest> <report>maven-changelog-plugin</report>
</build> <report>maven-changes-plugin</report>
<reports> <report>maven-checkstyle-plugin</report>
<report>maven-changelog-plugin</report> <report>maven-developer-activity-plugin</report>
<report>maven-changes-plugin</report> <report>maven-file-activity-plugin</report>
<report>maven-checkstyle-plugin</report> <report>maven-javadoc-plugin</report>
<!-- <report>maven-clover-plugin</report> --> <report>maven-jdepend-plugin</report>
<report>maven-developer-activity-plugin</report> <report>maven-junit-report-plugin</report>
<report>maven-file-activity-plugin</report> <report>maven-jxr-plugin</report>
<report>maven-javadoc-plugin</report> <report>maven-license-plugin</report>
<report>maven-jdepend-plugin</report> <report>maven-statcvs-plugin</report>
<report>maven-junit-report-plugin</report> <report>maven-tasklist-plugin</report>
<report>maven-jxr-plugin</report> <!--
<report>maven-license-plugin</report> <report>maven-clover-plugin</report>
<!-- <report>maven-linkcheck-plugin</report> --> <report>maven-linkcheck-plugin</report>
<report>maven-statcvs-plugin</report> -->
<report>maven-tasklist-plugin</report> </reports>
</reports>
</project> </project>

View File

@ -55,7 +55,7 @@ package org.apache.commons.math;
/** /**
* Signals a configuration problem with any of the factory methods. * Signals a configuration problem with any of the factory methods.
* @version $Revision: 1.6 $ $Date: 2003/08/09 04:03:41 $ * @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:34 $
*/ */
public class MathConfigurationException extends MathException { public class MathConfigurationException extends MathException {
@ -63,7 +63,7 @@ public class MathConfigurationException extends MathException {
* Default constructor. * Default constructor.
*/ */
public MathConfigurationException() { public MathConfigurationException() {
super(); this(null, null);
} }
/** /**
@ -71,7 +71,7 @@ public class MathConfigurationException extends MathException {
* @param message message describing the problem * @param message message describing the problem
*/ */
public MathConfigurationException(final String message) { public MathConfigurationException(final String message) {
super(message); this(message, null);
} }
/** /**
@ -90,6 +90,6 @@ public class MathConfigurationException extends MathException {
* @param throwable caught exception causing this problem * @param throwable caught exception causing this problem
*/ */
public MathConfigurationException(final Throwable throwable) { public MathConfigurationException(final Throwable throwable) {
super(throwable); this(null, throwable);
} }
} }

View File

@ -53,27 +53,31 @@
*/ */
package org.apache.commons.math; package org.apache.commons.math;
import org.apache.commons.lang.exception.NestableException;
/** /**
* A generic exception indicating problems in the math package. * A generic exception indicating problems in the math package.
* @version $Revision: 1.5 $ $Date: 2003/08/09 04:03:41 $ * @version $Revision: 1.6 $ $Date: 2003/09/27 04:13:34 $
*/ */
public class MathException extends Exception { public class MathException extends NestableException {
/** /**
* Constructs a MathException * Constructs a MathException
*/ */
public MathException() { public MathException() {
super(); this(null, null);
} }
/** /**
* Create an exception with a given error message.
* @param message message describing the problem * @param message message describing the problem
*/ */
public MathException(final String message) { public MathException(final String message) {
super(message); this(message, null);
} }
/** /**
* Create an exception with a given error message and root cause.
* @param message message describing the problem * @param message message describing the problem
* @param throwable caught exception causing this problem * @param throwable caught exception causing this problem
*/ */
@ -82,10 +86,10 @@ public class MathException extends Exception {
} }
/** /**
* Create an exception with a given root cause.
* @param throwable caught exception causing this problem * @param throwable caught exception causing this problem
*/ */
public MathException(final Throwable throwable) { public MathException(final Throwable throwable) {
super(throwable); this(null, throwable);
} }
} }

View File

@ -53,19 +53,28 @@
*/ */
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.lang.exception.NestableRuntimeException;
/** /**
* Error thrown when a numerical computation can not be performed because the * Error thrown when a numerical computation can not be performed because the
* numerical result failed to converge to a finite value. * numerical result failed to converge to a finite value.
* *
* @version $Revision: 1.2 $ $Date: 2003/07/09 20:02:43 $ * @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class ConvergenceException extends RuntimeException { public class ConvergenceException extends NestableRuntimeException {
/**
* Default constructor.
*/
public ConvergenceException() {
this(null, null);
}
/** /**
* Construct an exception with the given message. * Construct an exception with the given message.
* @param message descriptive error message. * @param message descriptive error message.
*/ */
public ConvergenceException(String message) { public ConvergenceException(String message) {
super(message); this(message, null);
} }
/** /**
@ -77,4 +86,12 @@ public class ConvergenceException extends RuntimeException {
super(message, cause); super(message, cause);
} }
/**
* Create an exception with a given root cause.
* @param throwable caught exception causing this problem
*/
public ConvergenceException(Throwable throwable) {
this(null, throwable);
}
} }

View File

@ -56,18 +56,66 @@ package org.apache.commons.math.analysis;
import org.apache.commons.math.MathException; import org.apache.commons.math.MathException;
/** /**
* Utility class comprised of root finding techniques. * Utility routines for {@link UnivariateRealSolver} objects.
* * @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:33 $
* @version $Revision: 1.4 $ $Date: 2003/09/07 03:12:56 $
*/ */
public class RootFinding { public class UnivariateRealSolverUtils {
/** /**
* Default constructor. Prohibit construction. * Default constructor.
*/ */
private RootFinding() { private UnivariateRealSolverUtils() {
super(); super();
} }
/**
* Method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/
public static double solve(UnivariateRealFunction f, double x0, double x1)
throws MathException
{
if(f == null){
throw new IllegalArgumentException("f can not be null.");
}
return UnivariateRealSolverFactory.newInstance().newDefaultSolver(f)
.solve(x0, x1);
}
/**
* Convience method to solve for zeros of real univariate functions. A
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @param absoluteAccuracy the accuracy to be used by the solver.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/
public static double solve(
UnivariateRealFunction f,
double x0,
double x1,
double absoluteAccuracy)
throws MathException
{
if(f == null){
throw new IllegalArgumentException("f can not be null.");
}
UnivariateRealSolver solver = UnivariateRealSolverFactory.newInstance()
.newDefaultSolver(f);
solver.setAbsoluteAccuracy(absoluteAccuracy);
return solver.solve(x0, x1);
}
/** /**
* For a function, f, this method returns two values, a and b that bracket * For a function, f, this method returns two values, a and b that bracket
* a root of f. That is to say, there exists a value c between a and b * a root of f. That is to say, there exists a value c between a and b
@ -114,7 +162,7 @@ public class RootFinding {
double fa; double fa;
double fb; double fb;
int numIterations = 0 ; int numIterations = 0 ;
do { do {
a = Math.max(a - 1.0, lowerBound); a = Math.max(a - 1.0, lowerBound);
b = Math.min(b + 1.0, upperBound); b = Math.min(b + 1.0, upperBound);
@ -122,7 +170,7 @@ public class RootFinding {
fb = function.value(b); fb = function.value(b);
numIterations += 1 ; numIterations += 1 ;
} while ( (fa * fb > 0.0) && ( numIterations < maximumIterations ) ); } while ( (fa * fb > 0.0) && ( numIterations < maximumIterations ) );
return new double[]{a, b}; return new double[]{a, b};
} }
} }

View File

@ -54,16 +54,15 @@
package org.apache.commons.math.stat.distribution; package org.apache.commons.math.stat.distribution;
import org.apache.commons.math.MathException; import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.RootFinding;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.UnivariateRealSolverUtil; import org.apache.commons.math.analysis.UnivariateRealSolverUtils;
/** /**
* Base class for various continuous distributions. It provides default * Base class for various continuous distributions. It provides default
* implementations for some of the methods that do not vary from distribution * implementations for some of the methods that do not vary from distribution
* to distribution. * to distribution.
* *
* @version $Revision: 1.8 $ $Date: 2003/07/30 21:58:11 $ * @version $Revision: 1.9 $ $Date: 2003/09/27 04:13:34 $
*/ */
public abstract class AbstractContinuousDistribution public abstract class AbstractContinuousDistribution
implements ContinuousDistribution { implements ContinuousDistribution {
@ -121,12 +120,12 @@ public abstract class AbstractContinuousDistribution
try { try {
// bracket root // bracket root
double[] bracket = RootFinding.bracket(rootFindingFunction, double[] bracket = UnivariateRealSolverUtils.bracket(rootFindingFunction,
getInitialDomain(p), getDomainLowerBound(p), getInitialDomain(p), getDomainLowerBound(p),
getDomainUpperBound(p)); getDomainUpperBound(p));
// find root // find root
double root = UnivariateRealSolverUtil.solve( double root = UnivariateRealSolverUtils.solve(
rootFindingFunction, bracket[0], bracket[1]); rootFindingFunction, bracket[0], bracket[1]);
return root; return root;

View File

@ -68,7 +68,7 @@ import org.apache.commons.math.stat.univariate.summary.SumOfSquares;
/** /**
* Provides univariate measures for an array of doubles. * Provides univariate measures for an array of doubles.
* @version $Revision: 1.3 $ $Date: 2003/09/26 19:30:32 $ * @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:33 $
*/ */
public abstract class AbstractUnivariate implements Univariate { public abstract class AbstractUnivariate implements Univariate {
@ -140,6 +140,11 @@ public abstract class AbstractUnivariate implements Univariate {
setWindowSize(window); setWindowSize(window);
} }
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
public abstract double apply(UnivariateStatistic stat); public abstract double apply(UnivariateStatistic stat);

View File

@ -62,7 +62,7 @@ import org.apache.commons.math.util.BeanTransformer;
* univariate statistics for a List of Java Beans by property. This * univariate statistics for a List of Java Beans by property. This
* implementation uses beanutils' PropertyUtils to get a simple, nested, * implementation uses beanutils' PropertyUtils to get a simple, nested,
* indexed, mapped, or combined property from an element of a List. * indexed, mapped, or combined property from an element of a List.
* @version $Revision: 1.6 $ $Date: 2003/09/26 19:30:32 $ * @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class BeanListUnivariateImpl extends ListUnivariateImpl { public class BeanListUnivariateImpl extends ListUnivariateImpl {
@ -77,7 +77,7 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
* @param list Backing List * @param list Backing List
*/ */
public BeanListUnivariateImpl(List list) { public BeanListUnivariateImpl(List list) {
super(list); this(list, null);
} }
/** /**
@ -89,7 +89,6 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
public BeanListUnivariateImpl(List list, String propertyName) { public BeanListUnivariateImpl(List list, String propertyName) {
super(list); super(list);
setPropertyName(propertyName); setPropertyName(propertyName);
this.transformer = new BeanTransformer(propertyName);
} }
/** /**
@ -103,9 +102,8 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
* @param propertyName Name of Property * @param propertyName Name of Property
*/ */
public void setPropertyName(String propertyName) { public void setPropertyName(String propertyName) {
System.out.println("Set prop name; " + propertyName);
this.propertyName = propertyName; this.propertyName = propertyName;
this.transformer = new BeanTransformer(propertyName); setTransformer(new BeanTransformer(propertyName));
} }
/** /**

View File

@ -63,7 +63,7 @@ import org.apache.commons.collections.HashBag;
* Accepts int, long or string values, converting * Accepts int, long or string values, converting
* all to Strings and maintaining frequency counts. * all to Strings and maintaining frequency counts.
* *
* @version $Revision: 1.4 $ $Date: 2003/07/09 21:45:23 $ * @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class Frequency { public class Frequency {
/** name for this frequency distribution. */ /** name for this frequency distribution. */
@ -85,7 +85,7 @@ public class Frequency {
*/ */
public Frequency(String name) { public Frequency(String name) {
super(); super();
this.name = name; setName(name);
} }
/** /**

View File

@ -60,7 +60,7 @@ import org.apache.commons.math.util.DefaultTransformer;
import org.apache.commons.math.util.NumberTransformer; import org.apache.commons.math.util.NumberTransformer;
/** /**
* @version $Revision: 1.6 $ $Date: 2003/09/26 19:30:32 $ * @version $Revision: 1.7 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class ListUnivariateImpl public class ListUnivariateImpl
extends AbstractStoreUnivariate extends AbstractStoreUnivariate
@ -80,9 +80,7 @@ public class ListUnivariateImpl
* @param list The list that will back this Univariate * @param list The list that will back this Univariate
*/ */
public ListUnivariateImpl(List list) { public ListUnivariateImpl(List list) {
super(); this(list, new DefaultTransformer());
this.list = list;
transformer = new DefaultTransformer();
} }
/** /**
@ -188,8 +186,10 @@ public class ListUnivariateImpl
list.clear(); list.clear();
} }
/* (non-Javadoc) /**
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic) * Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/ */
public double apply(UnivariateStatistic stat) { public double apply(UnivariateStatistic stat) {
double[] v = this.getValues(); double[] v = this.getValues();

View File

@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatistic;
import org.apache.commons.math.util.ContractableDoubleArray; import org.apache.commons.math.util.ContractableDoubleArray;
/** /**
* @version $Revision: 1.7 $ $Date: 2003/09/26 19:30:32 $ * @version $Revision: 1.8 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class StoreUnivariateImpl extends AbstractStoreUnivariate { public class StoreUnivariateImpl extends AbstractStoreUnivariate {
@ -144,8 +144,10 @@ public class StoreUnivariateImpl extends AbstractStoreUnivariate {
} }
} }
/* (non-Javadoc) /**
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic) * Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/ */
public double apply(UnivariateStatistic stat) { public double apply(UnivariateStatistic stat) {
if (eDA != null) { if (eDA != null) {

View File

@ -67,7 +67,7 @@ import org.apache.commons.math.util.FixedDoubleArray;
* Integers, floats and longs can be added, but they will be converted * Integers, floats and longs can be added, but they will be converted
* to doubles by addValue(). * to doubles by addValue().
* *
* @version $Revision: 1.20 $ $Date: 2003/09/26 19:30:32 $ * @version $Revision: 1.21 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class UnivariateImpl public class UnivariateImpl
extends AbstractUnivariate extends AbstractUnivariate
@ -161,8 +161,10 @@ public class UnivariateImpl
} }
} }
/* (non-Javadoc) /**
* @see org.apache.commons.math.stat.AbstractUnivariate#apply(org.apache.commons.math.stat.univariate.UnivariateStatistic) * Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/ */
public double apply(UnivariateStatistic stat) { public double apply(UnivariateStatistic stat) {

View File

@ -55,11 +55,11 @@ package org.apache.commons.math.util;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.math.MathException; import org.apache.commons.logging.LogFactory;
/** /**
* Uses PropertyUtils to map a Bean getter to a double value. * Uses PropertyUtils to map a Bean getter to a double value.
* @version $Revision: 1.5 $ $Date: 2003/09/17 19:19:09 $ * @version $Revision: 1.6 $ $Date: 2003/09/27 04:13:34 $
*/ */
public class BeanTransformer implements NumberTransformer { public class BeanTransformer implements NumberTransformer {
@ -72,7 +72,7 @@ public class BeanTransformer implements NumberTransformer {
* Create a BeanTransformer * Create a BeanTransformer
*/ */
public BeanTransformer() { public BeanTransformer() {
super(); this(null);
} }
/** /**
@ -80,26 +80,8 @@ public class BeanTransformer implements NumberTransformer {
* @param property The property. * @param property The property.
*/ */
public BeanTransformer(final String property) { public BeanTransformer(final String property) {
this.propertyName = property; super();
} setPropertyName(property);
/**
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(final Object o) throws MathException {
double d = Double.NaN;
try {
d =
((Number) PropertyUtils.getProperty(o, propertyName))
.doubleValue();
} catch (IllegalAccessException e) {
throw new MathException(e.getMessage(),e);
} catch (InvocationTargetException e) {
throw new MathException(e.getMessage(),e);
} catch (NoSuchMethodException e) {
throw new MathException(e.getMessage(),e);
}
return d;
} }
/** /**
@ -118,4 +100,26 @@ public class BeanTransformer implements NumberTransformer {
propertyName = string; propertyName = string;
} }
/**
* @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
public double transform(final Object o) {
double d = Double.NaN;
try {
d =
((Number) PropertyUtils.getProperty(o, getPropertyName()))
.doubleValue();
} catch (IllegalAccessException e) {
LogFactory.getLog(getClass()).error(
"Property can not be accessed. Using NaN.", e);
} catch (InvocationTargetException e) {
LogFactory.getLog(getClass()).error(
"Property accessor method threw an exception. Using NaN.", e);
e.printStackTrace();
} catch (NoSuchMethodException e) {
LogFactory.getLog(getClass()).error(
"Property accessor method does not exist. Using NaN.", e);
}
return d;
}
} }

View File

@ -51,28 +51,30 @@
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.commons.math.util; package org.apache.commons.math.util;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.converters.DoubleConverter;
/** /**
* A Default NumberTransformer for java.lang.Numbers and Numeric Strings. * A Default NumberTransformer for java.lang.Numbers and Numeric Strings.
* @version $Revision: 1.3 $ $Date: 2003/07/09 20:04:12 $ * @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:34 $
*/ */
public class DefaultTransformer implements NumberTransformer { public class DefaultTransformer implements NumberTransformer {
/** Converter used to transform objects. */
private static final DoubleConverter converter =
new DoubleConverter(new Double(Double.NaN));
/** /**
* @see org.apache.commons.collections.Transformer#transform(java.lang.Object) * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
*/ */
public double transform(Object o) { public double transform(Object o) {
double d = Double.NaN; double d;
try {
if (o instanceof Number) { d = ((Double)converter.convert(Double.class, o)).doubleValue();
return ((Number) o).doubleValue(); } catch(ConversionException ex){
} else { d = Double.NaN;
try {
d = Double.parseDouble(o.toString());
} catch (Exception e) {
e.printStackTrace();
}
} }
return d; return d;
} }

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathConfigurationExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
MathConfigurationException ex = new MathConfigurationException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
MathConfigurationException ex = new MathConfigurationException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathConfigurationException ex = new MathConfigurationException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathConfigurationException ex = new MathConfigurationException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class MathExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
MathException ex = new MathException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
MathException ex = new MathException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathException ex = new MathException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
MathException ex = new MathException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -58,16 +58,9 @@ import org.apache.commons.math.MathException;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* @version $Revision: 1.2 $ $Date: 2003/09/17 19:29:27 $ * @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:34 $
*/ */
public final class BisectionSolverTest extends TestCase { public final class BisectionSolverTest extends TestCase {
/**
*
*/
public BisectionSolverTest(String name) {
super(name);
}
/** /**
* *
*/ */
@ -124,4 +117,132 @@ public final class BisectionSolverTest extends TestCase {
result = solver.solve(0.85, 5); result = solver.solve(0.85, 5);
assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
} }
/**
*
*/
public void testSetFunctionValueAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setFunctionValueAccuracy(expected);
assertEquals(expected, solver.getFunctionValueAccuracy(), 1.0e-2);
} catch (MathException ex) {
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetFunctionValueAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getFunctionValueAccuracy();
solver.setFunctionValueAccuracy(newValue);
solver.resetFunctionValueAccuracy();
assertEquals(oldValue, solver.getFunctionValueAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetAbsoluteAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setAbsoluteAccuracy(expected);
assertEquals(expected, solver.getAbsoluteAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetAbsoluteAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getAbsoluteAccuracy();
solver.setAbsoluteAccuracy(newValue);
solver.resetAbsoluteAccuracy();
assertEquals(oldValue, solver.getAbsoluteAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetMaximalIterationCount(){
int expected = 100;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
solver.setMaximalIterationCount(expected);
assertEquals(expected, solver.getMaximalIterationCount());
}
/**
*
*/
public void testResetMaximalIterationCount(){
int newValue = 10000;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
int oldValue = solver.getMaximalIterationCount();
solver.setMaximalIterationCount(newValue);
solver.resetMaximalIterationCount();
assertEquals(oldValue, solver.getMaximalIterationCount());
}
/**
*
*/
public void testSetRelativeAccuracy(){
double expected = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
solver.setRelativeAccuracy(expected);
assertEquals(expected, solver.getRelativeAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testResetRelativeAccuracy(){
double newValue = 1.0e-2;
UnivariateRealFunction f = new QuinticFunction();
UnivariateRealSolver solver = new BisectionSolver(f);
try {
double oldValue = solver.getRelativeAccuracy();
solver.setRelativeAccuracy(newValue);
solver.resetRelativeAccuracy();
assertEquals(oldValue, solver.getRelativeAccuracy(), 1.0e-2);
} catch(MathException ex){
fail(ex.getMessage());
}
}
} }

View File

@ -0,0 +1,103 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.analysis;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class ConvergenceExceptionTest extends TestCase {
/**
*
*/
public void testConstructor(){
ConvergenceException ex = new ConvergenceException();
assertNull(ex.getCause());
assertNull(ex.getMessage());
}
/**
*
*/
public void testConstructorMessage(){
String msg = "message";
ConvergenceException ex = new ConvergenceException(msg);
assertNull(ex.getCause());
assertEquals(msg, ex.getMessage());
}
/**
*
*/
public void testConstructorMessageCause(){
String outMsg = "outer message";
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
ConvergenceException ex = new ConvergenceException(outMsg, cause);
assertEquals(outMsg, ex.getMessage());
assertEquals(cause, ex.getCause());
}
/**
*
*/
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
ConvergenceException ex = new ConvergenceException(cause);
assertEquals(cause, ex.getCause());
}
}

View File

@ -69,7 +69,7 @@ import junit.framework.TestSuite;
* default absolute accuracy of 10E-8 for sinus and the quintic function around * default absolute accuracy of 10E-8 for sinus and the quintic function around
* zero, and 5..10 iterations for the other zeros. * zero, and 5..10 iterations for the other zeros.
* *
* @version $Revision: 1.3 $ $Date: 2003/09/17 19:29:27 $ * @version $Revision: 1.4 $ $Date: 2003/09/27 04:13:34 $
*/ */
public final class RealSolverTest extends TestCase { public final class RealSolverTest extends TestCase {
@ -281,27 +281,27 @@ public final class RealSolverTest extends TestCase {
// 14 iterations on i586 JDK 1.4.1. // 14 iterations on i586 JDK 1.4.1.
assertTrue(solver.getIterationCount() <= 15); assertTrue(solver.getIterationCount() <= 15);
// Static solve method // Static solve method
result = UnivariateRealSolverUtil.solve(f, -0.2, 0.2); result = UnivariateRealSolverUtils.solve(f, -0.2, 0.2);
assertEquals(result, 0, solver.getAbsoluteAccuracy()); assertEquals(result, 0, solver.getAbsoluteAccuracy());
result = UnivariateRealSolverUtil.solve(f, -0.1, 0.3); result = UnivariateRealSolverUtils.solve(f, -0.1, 0.3);
Assert.assertEquals(result, 0, 1E-8); Assert.assertEquals(result, 0, 1E-8);
result = UnivariateRealSolverUtil.solve(f, -0.3, 0.45); result = UnivariateRealSolverUtils.solve(f, -0.3, 0.45);
Assert.assertEquals(result, 0, 1E-6); Assert.assertEquals(result, 0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.3, 0.7); result = UnivariateRealSolverUtils.solve(f, 0.3, 0.7);
Assert.assertEquals(result, 0.5, 1E-6); Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.2, 0.6); result = UnivariateRealSolverUtils.solve(f, 0.2, 0.6);
Assert.assertEquals(result, 0.5, 1E-6); Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.05, 0.95); result = UnivariateRealSolverUtils.solve(f, 0.05, 0.95);
Assert.assertEquals(result, 0.5, 1E-6); Assert.assertEquals(result, 0.5, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.25); result = UnivariateRealSolverUtils.solve(f, 0.85, 1.25);
Assert.assertEquals(result, 1.0, 1E-6); Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.8, 1.2); result = UnivariateRealSolverUtils.solve(f, 0.8, 1.2);
Assert.assertEquals(result, 1.0, 1E-6); Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 1.75); result = UnivariateRealSolverUtils.solve(f, 0.85, 1.75);
Assert.assertEquals(result, 1.0, 1E-6); Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.55, 1.45); result = UnivariateRealSolverUtils.solve(f, 0.55, 1.45);
Assert.assertEquals(result, 1.0, 1E-6); Assert.assertEquals(result, 1.0, 1E-6);
result = UnivariateRealSolverUtil.solve(f, 0.85, 5); result = UnivariateRealSolverUtils.solve(f, 0.85, 5);
Assert.assertEquals(result, 1.0, 1E-6); Assert.assertEquals(result, 1.0, 1E-6);
} }
} }

View File

@ -51,60 +51,70 @@
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.commons.math.analysis; package org.apache.commons.math.analysis;
import org.apache.commons.math.MathException; import org.apache.commons.math.MathException;
import junit.framework.TestCase;
/** /**
* Utility routines for {@link UnivariateRealSolver} objects. * @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
* @version $Revision: 1.2 $ $Date: 2003/09/07 03:12:56 $
*/ */
public class UnivariateRealSolverUtil { public class UnivariateRealSolverUtilsTest extends TestCase {
/** /**
* Default constructor. *
*/ */
private UnivariateRealSolverUtil() { public void testSolveNull(){
super(); try {
UnivariateRealSolverUtils.solve(null, 0.0, 4.0);
fail();
} catch(MathException ex){
fail("math exception should no be thrown.");
} catch(IllegalArgumentException ex){
// success
}
}
/**
*
*/
public void testSolveSin(){
try {
double x = UnivariateRealSolverUtils.solve(new SinFunction(), 1.0,
4.0);
assertEquals(Math.PI, x, 1.0e-4);
} catch(MathException ex){
fail("math exception should no be thrown.");
}
} }
/** /**
* Method to solve for zeros of real univariate functions. A *
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/ */
public static double solve(UnivariateRealFunction f, double x0, double x1) public void testSolveAccuracyNull(){
throws MathException { try {
double accuracy = 1.0e-6;
return UnivariateRealSolverFactory.newInstance().newDefaultSolver(f) UnivariateRealSolverUtils.solve(null, 0.0, 4.0, accuracy);
.solve(x0, x1); fail();
} catch(MathException ex){
fail("math exception should no be thrown.");
} catch(IllegalArgumentException ex){
// success
}
} }
/** /**
* Convience method to solve for zeros of real univariate functions. A *
* default solver is created and used for solving.
* @param f the function.
* @param x0 the lower bound for the interval.
* @param x1 the upper bound for the interval.
* @param absoluteAccuracy the accuracy to be used by the solver.
* @return a value where the function is zero.
* @throws MathException if the iteration count was exceeded or the
* solver detects convergence problems otherwise.
*/ */
public static double solve( public void testSolveAccuracySin(){
UnivariateRealFunction f, try {
double x0, double accuracy = 1.0e-6;
double x1, double x = UnivariateRealSolverUtils.solve(new SinFunction(), 1.0,
double absoluteAccuracy) 4.0, accuracy);
throws MathException { assertEquals(Math.PI, x, accuracy);
} catch(MathException ex){
UnivariateRealSolver solver = UnivariateRealSolverFactory.newInstance() fail("math exception should no be thrown.");
.newDefaultSolver(f); }
solver.setAbsoluteAccuracy(absoluteAccuracy);
return solver.solve(x0, x1);
} }
} }

View File

@ -57,26 +57,31 @@ package org.apache.commons.math.stat.distribution;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* @version $Revision: 1.4 $ $Date: 2003/09/17 19:29:30 $ * @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/ */
public class GammaDistributionTest extends TestCase { public class GammaDistributionTest extends TestCase {
/**
* Constructor for ChiSquareDistributionTest.
* @param name
*/
public GammaDistributionTest(String name) {
super(name);
}
public void testProbabilities(){ public void testProbabilities(){
testProbability(15.5, 4.0, 2.0, .9499); testProbability(-1.000, 4.0, 2.0, .0000);
testProbability( 0.5, 4.0, 1.0, .0018); testProbability(15.501, 4.0, 2.0, .9499);
testProbability(10.0, 1.0, 2.0, .9933); testProbability( 0.504, 4.0, 1.0, .0018);
testProbability( 5.0, 2.0, 2.0, .7127); testProbability(10.011, 1.0, 2.0, .9933);
testProbability( 5.000, 2.0, 2.0, .7127);
} }
public void testValues(){
testValue(15.501, 4.0, 2.0, .9499);
testValue( 0.504, 4.0, 1.0, .0018);
testValue(10.011, 1.0, 2.0, .9933);
testValue( 5.000, 2.0, 2.0, .7127);
}
private void testProbability(double x, double a, double b, double expected){ private void testProbability(double x, double a, double b, double expected){
double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).cummulativeProbability(x); double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).cummulativeProbability(x);
assertEquals("probability for " + x, expected, actual, 10e-4); assertEquals("probability for " + x, expected, actual, 10e-4);
} }
private void testValue(double expected, double a, double b, double p){
double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).inverseCummulativeProbability(p);
assertEquals("critical value for " + p, expected, actual, 10e-4);
}
} }

View File

@ -65,7 +65,7 @@ import org.apache.commons.math.beans.*;
/** /**
* Test cases for the {@link BeanListUnivariateImpl} class. * Test cases for the {@link BeanListUnivariateImpl} class.
* *
* @version $Revision: 1.4 $ $Date: 2003/09/17 19:29:32 $ * @version $Revision: 1.5 $ $Date: 2003/09/27 04:13:33 $
*/ */
public final class BeanListUnivariateImplTest extends TestCase { public final class BeanListUnivariateImplTest extends TestCase {
@ -137,5 +137,12 @@ public final class BeanListUnivariateImplTest extends TestCase {
ageU.getMax(), 0.001 ); ageU.getMax(), 0.001 );
} }
public void testSetPropertyName(){
BeanListUnivariateImpl u = new BeanListUnivariateImpl(null);
String expected = "property";
u.setPropertyName(expected);
assertEquals(expected, u.getPropertyName());
}
} }

View File

@ -53,6 +53,10 @@
*/ */
package org.apache.commons.math.stat; package org.apache.commons.math.stat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -60,7 +64,7 @@ import junit.framework.TestSuite;
/** /**
* Test cases for the {@link Frequency} class. * Test cases for the {@link Frequency} class.
* *
* @version $Revision: 1.2 $ $Date: 2003/07/07 23:19:19 $ * @version $Revision: 1.3 $ $Date: 2003/09/27 04:13:33 $
*/ */
public final class FrequencyTest extends TestCase { public final class FrequencyTest extends TestCase {
@ -103,7 +107,7 @@ public final class FrequencyTest extends TestCase {
/** test pcts */ /** test pcts */
public void testPcts() { public void testPcts() {
Frequency f = new Frequency("test counts"); Frequency f = new Frequency("test pcts");
f.addValue(oneL); f.addValue(oneL);
f.addValue(twoL); f.addValue(twoL);
f.addValue(oneI); f.addValue(oneI);
@ -116,6 +120,46 @@ public final class FrequencyTest extends TestCase {
assertEquals("two pct",0.25,f.getPct("2"),tolerance); assertEquals("two pct",0.25,f.getPct("2"),tolerance);
assertEquals("foo pct",0.5,f.getPct("foo"),tolerance); assertEquals("foo pct",0.5,f.getPct("foo"),tolerance);
assertEquals("bar pct",0,f.getPct("bar"),tolerance); assertEquals("bar pct",0,f.getPct("bar"),tolerance);
} }
/**
*
*/
public void testToString(){
Frequency f = new Frequency("test toString");
f.addValue(oneL);
f.addValue(twoL);
f.addValue(oneI);
f.addValue(twoI);
String s = f.toString();
assertNotNull(s);
BufferedReader reader = new BufferedReader(new StringReader(s));
try {
String line = reader.readLine(); // header line
assertNotNull(line);
line = reader.readLine(); // one's or two's line
assertNotNull(line);
line = reader.readLine(); // one's or two's line
assertNotNull(line);
line = reader.readLine(); // no more elements
assertNull(line);
} catch(IOException ex){
fail(ex.getMessage());
}
}
/**
*
*/
public void testSetName(){
String name = "name";
Frequency f = new Frequency();
f.setName(name);
assertEquals(name, f.getName());
}
} }

View File

@ -0,0 +1,136 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import org.apache.commons.math.TestUtils;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class BeanTransformerTest extends TestCase {
/**
*
*/
public void testConstructor(){
BeanTransformer b = new BeanTransformer();
assertNull(b.getPropertyName());
}
/**
*
*/
public void testConstructorString(){
String name = "property";
BeanTransformer b = new BeanTransformer(name);
assertEquals(name, b.getPropertyName());
}
/**
*
*/
public void testSetPropertyName(){
String name = "property";
BeanTransformer b = new BeanTransformer();
b.setPropertyName(name);
assertEquals(name, b.getPropertyName());
}
/**
*
*/
public void testTransformNoSuchMethod(){
BeanTransformer b = new BeanTransformer("z");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
}
/**
*
*/
public void testTransform(){
BeanTransformer b = new BeanTransformer("x");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(1.0, value, 1.0e-2);
}
/**
*
*/
public void testTransformInvocationError(){
BeanTransformer b = new BeanTransformer("z");
TestBean target = new TestBean();
double value = b.transform(target);
TestUtils.assertEquals(Double.NaN, value, 1.0e-2);
}
/**
*
*/
public void testTransformInvalidType(){
BeanTransformer b = new BeanTransformer("y");
TestBean target = new TestBean();
try {
b.transform(target);
fail();
} catch(ClassCastException ex){
// success
}
}
}

View File

@ -0,0 +1,125 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import java.math.BigDecimal;
import org.apache.commons.math.TestUtils;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class DefaultTransformerTest extends TestCase {
/**
*
*/
public void testTransformDouble(){
double expected = 1.0;
Double input = new Double(expected);
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformNull(){
double expected = Double.NaN;
DefaultTransformer t = new DefaultTransformer();
TestUtils.assertEquals(expected, t.transform(null), 1.0e-4);
}
/**
*
*/
public void testTransformInteger(){
double expected = 1.0;
Integer input = new Integer(1);
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformBigDecimal(){
double expected = 1.0;
BigDecimal input = new BigDecimal("1.0");
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformString(){
double expected = 1.0;
String input = "1.0";
DefaultTransformer t = new DefaultTransformer();
assertEquals(expected, t.transform(input), 1.0e-4);
}
/**
*
*/
public void testTransformObject(){
double expected = Double.NaN;
Boolean input = Boolean.TRUE;
DefaultTransformer t = new DefaultTransformer();
TestUtils.assertEquals(expected, t.transform(input), 1.0e-4);
}
}

View File

@ -0,0 +1,109 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class TestBean {
private Double x = new Double(1.0);
private String y = "1.0";
private Double z = new Double(2.0);
/**
*
*/
public Double getX() {
return x;
}
/**
*
*/
public String getY() {
return y;
}
/**
*
*/
public void setX(Double double1) {
x = double1;
}
/**
*
*/
public void setY(String string) {
y = string;
}
/**
*
*/
public Double getZ() {
throw new RuntimeException();
}
/**
*
*/
public void setZ(Double double1) {
z = double1;
}
}

View File

@ -0,0 +1,141 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.util;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2003/09/27 04:13:34 $
*/
public class TransformerMapTest extends TestCase {
/**
*
*/
public void testPutTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertEquals(expected, map.getTransformer(TransformerMapTest.class));
}
/**
*
*/
public void testContainsClass(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
}
/**
*
*/
public void testContainsTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsTransformer(expected));
}
/**
*
*/
public void testRemoveTransformer(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
assertTrue(map.containsTransformer(expected));
map.removeTransformer(TransformerMapTest.class);
assertFalse(map.containsClass(TransformerMapTest.class));
assertFalse(map.containsTransformer(expected));
}
/**
*
*/
public void testClear(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.containsClass(TransformerMapTest.class));
map.clear();
assertFalse(map.containsClass(TransformerMapTest.class));
}
/**
*
*/
public void testClasses(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.classes().contains(TransformerMapTest.class));
}
/**
*
*/
public void testTransformers(){
NumberTransformer expected = new DefaultTransformer();
TransformerMap map = new TransformerMap();
map.putTransformer(TransformerMapTest.class, expected);
assertTrue(map.transformers().contains(expected));
}
}