Few tests for the error functions.

This commit is contained in:
jruoho 2011-09-17 12:00:50 +00:00
parent 20aafc300b
commit 99d89af157
3 changed files with 336 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.386 2011/09/17 08:15:43 jruoho Exp $
# $NetBSD: mi,v 1.387 2011/09/17 12:00:50 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -548,6 +548,7 @@
./usr/libdata/debug/usr/tests/lib/libm tests-lib-debug
./usr/libdata/debug/usr/tests/lib/libm/t_ceil.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_cos.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_erf.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug tests-lib-debug debug,atf
@ -2258,6 +2259,7 @@
./usr/tests/lib/libm/Atffile tests-lib-tests atf
./usr/tests/lib/libm/t_ceil tests-lib-tests atf
./usr/tests/lib/libm/t_cos tests-lib-tests atf
./usr/tests/lib/libm/t_erf tests-lib-tests atf
./usr/tests/lib/libm/t_floor tests-obsolete obsolete
./usr/tests/lib/libm/t_infinity tests-lib-tests atf
./usr/tests/lib/libm/t_ldexp tests-lib-tests atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.10 2011/09/17 08:15:43 jruoho Exp $
# $NetBSD: Makefile,v 1.11 2011/09/17 12:00:50 jruoho Exp $
.include <bsd.own.mk>
@ -6,6 +6,7 @@ TESTSDIR= ${TESTSBASE}/lib/libm
TESTS_C+= t_ceil
TESTS_C+= t_cos
TESTS_C+= t_erf
TESTS_C+= t_infinity
TESTS_C+= t_ldexp
TESTS_C+= t_log

331
tests/lib/libm/t_erf.c Normal file
View File

@ -0,0 +1,331 @@
/* $NetBSD: t_erf.c,v 1.1 2011/09/17 12:00:50 jruoho Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jukka Ruohonen.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS 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 FOUNDATION OR 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.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_erf.c,v 1.1 2011/09/17 12:00:50 jruoho Exp $");
#include <atf-c.h>
#include <math.h>
/*
* erf(3)
*/
ATF_TC(erf_nan);
ATF_TC_HEAD(erf_nan, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erf(NaN) == NaN");
}
ATF_TC_BODY(erf_nan, tc)
{
#ifndef __vax__
const double x = 0.0L / 0.0L;
ATF_CHECK(isnan(erf(x)) != 0);
#endif
}
ATF_TC(erf_inf_neg);
ATF_TC_HEAD(erf_inf_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erf(-Inf) == -1.0");
}
ATF_TC_BODY(erf_inf_neg, tc)
{
#ifndef __vax__
const double x = -1.0L / 0.0L;
if (erf(x) != -1.0)
atf_tc_fail_nonfatal("erf(-Inf) != -1.0");
#endif
}
ATF_TC(erf_inf_pos);
ATF_TC_HEAD(erf_inf_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erf(+Inf) == 1.0");
}
ATF_TC_BODY(erf_inf_pos, tc)
{
#ifndef __vax__
const double x = 1.0L / 0.0L;
if (erf(x) != 1.0)
atf_tc_fail_nonfatal("erf(+Inf) != 1.0");
#endif
}
ATF_TC(erf_zero_neg);
ATF_TC_HEAD(erf_zero_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erf(-0.0) == -0.0");
}
ATF_TC_BODY(erf_zero_neg, tc)
{
#ifndef __vax__
const double x = -0.0L;
double y = erf(x);
if (fabs(y) > 0.0 || signbit(y) == 0)
atf_tc_fail_nonfatal("erf(-0.0) != -0.0");
#endif
}
ATF_TC(erf_zero_pos);
ATF_TC_HEAD(erf_zero_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erf(+0.0) == +0.0");
}
ATF_TC_BODY(erf_zero_pos, tc)
{
#ifndef __vax__
const double x = 0.0L;
double y = erf(x);
if (fabs(y) > 0.0 || signbit(y) != 0)
atf_tc_fail_nonfatal("erf(+0.0) != +0.0");
#endif
}
/*
* erff(3)
*/
ATF_TC(erff_nan);
ATF_TC_HEAD(erff_nan, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erff(NaN) == NaN");
}
ATF_TC_BODY(erff_nan, tc)
{
#ifndef __vax__
const float x = 0.0L / 0.0L;
ATF_CHECK(isnan(erff(x)) != 0);
#endif
}
ATF_TC(erff_inf_neg);
ATF_TC_HEAD(erff_inf_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erff(-Inf) == -1.0");
}
ATF_TC_BODY(erff_inf_neg, tc)
{
#ifndef __vax__
const float x = -1.0L / 0.0L;
if (erff(x) != -1.0)
atf_tc_fail_nonfatal("erff(-Inf) != -1.0");
#endif
}
ATF_TC(erff_inf_pos);
ATF_TC_HEAD(erff_inf_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erff(+Inf) == 1.0");
}
ATF_TC_BODY(erff_inf_pos, tc)
{
#ifndef __vax__
const float x = 1.0L / 0.0L;
if (erff(x) != 1.0)
atf_tc_fail_nonfatal("erff(+Inf) != 1.0");
#endif
}
ATF_TC(erff_zero_neg);
ATF_TC_HEAD(erff_zero_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erff(-0.0) == -0.0");
}
ATF_TC_BODY(erff_zero_neg, tc)
{
#ifndef __vax__
const float x = -0.0L;
float y = erff(x);
if (fabsf(y) > 0.0 || signbit(y) == 0)
atf_tc_fail_nonfatal("erff(-0.0) != -0.0");
#endif
}
ATF_TC(erff_zero_pos);
ATF_TC_HEAD(erff_zero_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erff(+0.0) == +0.0");
}
ATF_TC_BODY(erff_zero_pos, tc)
{
#ifndef __vax__
const float x = 0.0L;
float y = erff(x);
if (fabsf(y) > 0.0 || signbit(y) != 0)
atf_tc_fail_nonfatal("erff(+0.0) != +0.0");
#endif
}
/*
* erfc(3)
*/
ATF_TC(erfc_nan);
ATF_TC_HEAD(erfc_nan, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfc(NaN) == NaN");
}
ATF_TC_BODY(erfc_nan, tc)
{
#ifndef __vax__
const double x = 0.0L / 0.0L;
ATF_CHECK(isnan(erfc(x)) != 0);
#endif
}
ATF_TC(erfc_inf_neg);
ATF_TC_HEAD(erfc_inf_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfc(-Inf) == 2.0");
}
ATF_TC_BODY(erfc_inf_neg, tc)
{
#ifndef __vax__
const double x = -1.0L / 0.0L;
if (erfc(x) != 2.0)
atf_tc_fail_nonfatal("erfc(-Inf) != 2.0");
#endif
}
ATF_TC(erfc_inf_pos);
ATF_TC_HEAD(erfc_inf_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfc(+Inf) == +0.0");
}
ATF_TC_BODY(erfc_inf_pos, tc)
{
#ifndef __vax__
const double x = 1.0L / 0.0L;
double y = erfc(x);
if (fabs(y) > 0.0 || signbit(y) != 0)
atf_tc_fail_nonfatal("erfc(+Inf) != +0.0");
#endif
}
/*
* erfcf(3)
*/
ATF_TC(erfcf_nan);
ATF_TC_HEAD(erfcf_nan, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfcf(NaN) == NaN");
}
ATF_TC_BODY(erfcf_nan, tc)
{
#ifndef __vax__
const float x = 0.0L / 0.0L;
ATF_CHECK(isnan(erfcf(x)) != 0);
#endif
}
ATF_TC(erfcf_inf_neg);
ATF_TC_HEAD(erfcf_inf_neg, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfcf(-Inf) == 2.0");
}
ATF_TC_BODY(erfcf_inf_neg, tc)
{
#ifndef __vax__
const float x = -1.0L / 0.0L;
if (erfcf(x) != 2.0)
atf_tc_fail_nonfatal("erfcf(-Inf) != 2.0");
#endif
}
ATF_TC(erfcf_inf_pos);
ATF_TC_HEAD(erfcf_inf_pos, tc)
{
atf_tc_set_md_var(tc, "descr", "Test erfcf(+Inf) == +0.0");
}
ATF_TC_BODY(erfcf_inf_pos, tc)
{
#ifndef __vax__
const float x = 1.0L / 0.0L;
float y = erfcf(x);
if (fabsf(y) > 0.0 || signbit(y) != 0)
atf_tc_fail_nonfatal("erfcf(+Inf) != +0.0");
#endif
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, erf_nan);
ATF_TP_ADD_TC(tp, erf_inf_neg);
ATF_TP_ADD_TC(tp, erf_inf_pos);
ATF_TP_ADD_TC(tp, erf_zero_neg);
ATF_TP_ADD_TC(tp, erf_zero_pos);
ATF_TP_ADD_TC(tp, erff_nan);
ATF_TP_ADD_TC(tp, erff_inf_neg);
ATF_TP_ADD_TC(tp, erff_inf_pos);
ATF_TP_ADD_TC(tp, erff_zero_neg);
ATF_TP_ADD_TC(tp, erff_zero_pos);
ATF_TP_ADD_TC(tp, erfc_nan);
ATF_TP_ADD_TC(tp, erfc_inf_neg);
ATF_TP_ADD_TC(tp, erfc_inf_pos);
ATF_TP_ADD_TC(tp, erfcf_nan);
ATF_TP_ADD_TC(tp, erfcf_inf_neg);
ATF_TP_ADD_TC(tp, erfcf_inf_pos);
return atf_no_error();
}