1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.commons.math.special;
19  
20  import org.apache.commons.math.MathException;
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
26   */
27  public class ErfTest extends TestCase {
28  
29      public void testErf0() throws MathException {
30          double actual = Erf.erf(0.0);
31          double expected = 0.0;
32          assertEquals(expected, actual, 1.0e-5);
33      }
34  
35      public void testErf1960() throws MathException {
36          double x = 1.960 / Math.sqrt(2.0);
37          double actual = Erf.erf(x);
38          double expected = 0.95;
39          assertEquals(expected, actual, 1.0e-5);
40  
41          actual = Erf.erf(-x);
42          expected = -expected;
43          assertEquals(expected, actual, 1.0e-5);
44      }
45  
46      public void testErf2576() throws MathException {
47          double x = 2.576 / Math.sqrt(2.0);
48          double actual = Erf.erf(x);
49          double expected = 0.99;
50          assertEquals(expected, actual, 1.0e-5);
51      
52          actual = Erf.erf(-x);
53          expected = -expected;
54          assertEquals(expected, actual, 1.0e-5);
55      }
56  
57      public void testErf2807() throws MathException {
58          double x = 2.807 / Math.sqrt(2.0);
59          double actual = Erf.erf(x);
60          double expected = 0.995;
61          assertEquals(expected, actual, 1.0e-5);
62          
63          actual = Erf.erf(-x);
64          expected = -expected;
65          assertEquals(expected, actual, 1.0e-5);
66      }
67  
68      public void testErf3291() throws MathException {
69          double x = 3.291 / Math.sqrt(2.0);
70          double actual = Erf.erf(x);
71          double expected = 0.999;
72          assertEquals(expected, actual, 1.0e-5);
73          
74          actual = Erf.erf(-x);
75          expected = -expected;
76          assertEquals(expected, actual, 1.0e-5);
77      }
78  }