1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.commons.math.analysis;
20  
21  import junit.framework.TestCase;
22  
23  /**
24   * @version $Revision: 566833 $ $Date: 2007-08-16 13:36:33 -0700 (Thu, 16 Aug 2007) $
25   */
26  public class UnivariateRealSolverFactoryImplTest extends TestCase {
27      
28      /** solver factory */
29      private UnivariateRealSolverFactory factory;
30      
31      /** function */
32      private DifferentiableUnivariateRealFunction function;
33      /**
34       * @throws java.lang.Exception
35       * @see junit.framework.TestCase#tearDown()
36       */
37      protected void setUp() throws Exception {
38          super.setUp();
39          factory = new UnivariateRealSolverFactoryImpl();
40          function = new SinFunction();
41      }
42      
43      /**
44       * @throws java.lang.Exception
45       * @see junit.framework.TestCase#tearDown()
46       */
47      protected void tearDown() throws Exception {
48          factory = null;
49          function = null;
50          super.tearDown();
51      }
52  
53      public void testNewBisectionSolverNull() {
54          try {
55              factory.newBisectionSolver(null);
56              fail();
57          } catch(IllegalArgumentException ex) {
58              // success
59          }
60      }
61  
62      public void testNewBisectionSolverValid() {
63          UnivariateRealSolver solver = factory.newBisectionSolver(function);
64          assertNotNull(solver);
65          assertTrue(solver instanceof BisectionSolver);
66      }
67  
68      public void testNewNewtonSolverNull() {
69          try {
70              factory.newNewtonSolver(null);
71              fail();
72          } catch(IllegalArgumentException ex) {
73              // success
74          }
75      }
76  
77      public void testNewNewtonSolverValid() {
78          UnivariateRealSolver solver = factory.newNewtonSolver(function);
79          assertNotNull(solver);
80          assertTrue(solver instanceof NewtonSolver);
81      }
82  
83      public void testNewBrentSolverNull() {
84          try {
85              factory.newBrentSolver(null);
86              fail();
87          } catch(IllegalArgumentException ex) {
88              // success
89          }
90      }
91  
92      public void testNewBrentSolverValid() {
93          UnivariateRealSolver solver = factory.newBrentSolver(function);
94          assertNotNull(solver);
95          assertTrue(solver instanceof BrentSolver);
96      }
97  
98      public void testNewSecantSolverNull() {
99          try {
100             factory.newSecantSolver(null);
101             fail();
102         } catch(IllegalArgumentException ex) {
103             // success
104         }
105     }
106 
107     public void testNewSecantSolverValid() {
108         UnivariateRealSolver solver = factory.newSecantSolver(function);
109         assertNotNull(solver);
110         assertTrue(solver instanceof SecantSolver);
111     }
112 }