001: /*
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.math.analysis;
019:
020: import junit.framework.TestCase;
021:
022: /**
023: * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
024: */
025: public class UnivariateRealSolverFactoryImplTest extends TestCase {
026:
027: /** solver factory */
028: private UnivariateRealSolverFactory factory;
029:
030: /** function */
031: private DifferentiableUnivariateRealFunction function;
032:
033: /**
034: * @throws java.lang.Exception
035: * @see junit.framework.TestCase#tearDown()
036: */
037: protected void setUp() throws Exception {
038: super .setUp();
039: factory = new UnivariateRealSolverFactoryImpl();
040: function = new SinFunction();
041: }
042:
043: /**
044: * @throws java.lang.Exception
045: * @see junit.framework.TestCase#tearDown()
046: */
047: protected void tearDown() throws Exception {
048: factory = null;
049: function = null;
050: super .tearDown();
051: }
052:
053: public void testNewBisectionSolverNull() {
054: try {
055: UnivariateRealSolver solver = factory
056: .newBisectionSolver(null);
057: fail();
058: } catch (IllegalArgumentException ex) {
059: // success
060: }
061: }
062:
063: public void testNewBisectionSolverValid() {
064: UnivariateRealSolver solver = factory
065: .newBisectionSolver(function);
066: assertNotNull(solver);
067: assertTrue(solver instanceof BisectionSolver);
068: }
069:
070: public void testNewNewtonSolverNull() {
071: try {
072: UnivariateRealSolver solver = factory.newNewtonSolver(null);
073: fail();
074: } catch (IllegalArgumentException ex) {
075: // success
076: }
077: }
078:
079: public void testNewNewtonSolverValid() {
080: UnivariateRealSolver solver = factory.newNewtonSolver(function);
081: assertNotNull(solver);
082: assertTrue(solver instanceof NewtonSolver);
083: }
084:
085: public void testNewBrentSolverNull() {
086: try {
087: UnivariateRealSolver solver = factory.newBrentSolver(null);
088: fail();
089: } catch (IllegalArgumentException ex) {
090: // success
091: }
092: }
093:
094: public void testNewBrentSolverValid() {
095: UnivariateRealSolver solver = factory.newBrentSolver(function);
096: assertNotNull(solver);
097: assertTrue(solver instanceof BrentSolver);
098: }
099:
100: public void testNewSecantSolverNull() {
101: try {
102: UnivariateRealSolver solver = factory.newSecantSolver(null);
103: fail();
104: } catch (IllegalArgumentException ex) {
105: // success
106: }
107: }
108:
109: public void testNewSecantSolverValid() {
110: UnivariateRealSolver solver = factory.newSecantSolver(function);
111: assertNotNull(solver);
112: assertTrue(solver instanceof SecantSolver);
113: }
114: }
|