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