Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libm Use a pre-calculated value as expected result...
details: https://anonhg.NetBSD.org/src/rev/a65bb07f47a8
branches: trunk
changeset: 785986:a65bb07f47a8
user: isaki <isaki%NetBSD.org@localhost>
date: Tue Apr 09 12:11:04 2013 +0000
description:
Use a pre-calculated value as expected result, instead of
comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
diffstat:
tests/lib/libm/t_acos.c | 66 ++++++++++++++++++++----------------
tests/lib/libm/t_asin.c | 65 ++++++++++++++++++++---------------
tests/lib/libm/t_atan.c | 63 +++++++++++++++++++---------------
tests/lib/libm/t_cosh.c | 88 ++++++++++++++++++++++++++----------------------
tests/lib/libm/t_sinh.c | 87 ++++++++++++++++++++++++++----------------------
5 files changed, 204 insertions(+), 165 deletions(-)
diffs (truncated from 661 to 300 lines):
diff -r 09ad72e1163d -r a65bb07f47a8 tests/lib/libm/t_acos.c
--- a/tests/lib/libm/t_acos.c Tue Apr 09 11:42:56 2013 +0000
+++ b/tests/lib/libm/t_acos.c Tue Apr 09 12:11:04 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_acos.c,v 1.3 2012/03/23 23:45:31 matt Exp $ */
+/* $NetBSD: t_acos.c,v 1.4 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,6 +32,20 @@
#include <atf-c.h>
#include <math.h>
+static const struct {
+ double x;
+ double y;
+} values[] = {
+ { -1, M_PI, },
+ { -0.99, 3.000053180265366, },
+ { -0.5, 2.094395102393195, },
+ { -0.1, 1.670963747956456, },
+ { 0, M_PI / 2, },
+ { 0.1, 1.470628905633337, },
+ { 0.5, 1.047197551196598, },
+ { 0.99, 0.141539473324427, },
+};
+
/*
* acos(3)
*/
@@ -119,28 +133,25 @@
#endif
}
-ATF_TC(acos_cos);
-ATF_TC_HEAD(acos_cos, tc)
+ATF_TC(acos_inrange);
+ATF_TC_HEAD(acos_inrange, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test acos(cos(x)) == x");
+ atf_tc_set_md_var(tc, "descr", "Test acos(x) for some values");
}
-ATF_TC_BODY(acos_cos, tc)
+ATF_TC_BODY(acos_inrange, tc)
{
#ifndef __vax__
- const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const double eps = 1.0e-15;
+ double x;
double y;
size_t i;
- for (i = 0; i < __arraycount(x); i++) {
-
- y = acos(cos(x[i]));
-
- if (fabs(y - x[i]) > eps)
- atf_tc_fail_nonfatal(
- "acos(cos(%0.03f)) != %0.03f (eps=%0.03e)",
- x[i], x[i], fabs(y - x[i]));
+ for (i = 0; i < __arraycount(values); i++) {
+ x = values[i].x;
+ y = values[i].y;
+ if (fabs(acos(x) - y) > eps)
+ atf_tc_fail_nonfatal("acos(%g) != %g", x, y);
}
#endif
}
@@ -232,28 +243,25 @@
#endif
}
-ATF_TC(acosf_cosf);
-ATF_TC_HEAD(acosf_cosf, tc)
+ATF_TC(acosf_inrange);
+ATF_TC_HEAD(acosf_inrange, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test acosf(cosf(x)) == x");
+ atf_tc_set_md_var(tc, "descr", "Test acosf(x) for some values");
}
-ATF_TC_BODY(acosf_cosf, tc)
+ATF_TC_BODY(acosf_inrange, tc)
{
#ifndef __vax__
- const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const float eps = 1.0e-5;
+ float x;
float y;
size_t i;
- for (i = 0; i < __arraycount(x); i++) {
-
- y = acosf(cosf(x[i]));
-
- if (fabsf(y - x[i]) > eps)
- atf_tc_fail_nonfatal(
- "acosf(cosf(%0.03f)) != %0.03f (eps=%0.03e)",
- x[i], x[i], fabs(y - x[i]));
+ for (i = 0; i < __arraycount(values); i++) {
+ x = values[i].x;
+ y = values[i].y;
+ if (fabsf(acosf(x) - y) > eps)
+ atf_tc_fail_nonfatal("acosf(%g) != %g", x, y);
}
#endif
}
@@ -266,14 +274,14 @@
ATF_TP_ADD_TC(tp, acos_inf_pos);
ATF_TP_ADD_TC(tp, acos_one_pos);
ATF_TP_ADD_TC(tp, acos_range);
- ATF_TP_ADD_TC(tp, acos_cos);
+ ATF_TP_ADD_TC(tp, acos_inrange);
ATF_TP_ADD_TC(tp, acosf_nan);
ATF_TP_ADD_TC(tp, acosf_inf_neg);
ATF_TP_ADD_TC(tp, acosf_inf_pos);
ATF_TP_ADD_TC(tp, acosf_one_pos);
ATF_TP_ADD_TC(tp, acosf_range);
- ATF_TP_ADD_TC(tp, acosf_cosf);
+ ATF_TP_ADD_TC(tp, acosf_inrange);
return atf_no_error();
}
diff -r 09ad72e1163d -r a65bb07f47a8 tests/lib/libm/t_asin.c
--- a/tests/lib/libm/t_asin.c Tue Apr 09 11:42:56 2013 +0000
+++ b/tests/lib/libm/t_asin.c Tue Apr 09 12:11:04 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_asin.c,v 1.1 2011/09/17 18:08:35 jruoho Exp $ */
+/* $NetBSD: t_asin.c,v 1.2 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,6 +32,20 @@
#include <atf-c.h>
#include <math.h>
+static const struct {
+ double x;
+ double y;
+} values[] = {
+ { -1.0, -M_PI / 2, },
+ { -0.9, -1.119769514998634, },
+ { -0.5, -M_PI / 6, },
+ { -0.1, -0.1001674211615598, },
+ { 0.1, 0.1001674211615598, },
+ { 0.5, M_PI / 6, },
+ { 0.9, 1.119769514998634, },
+ { 1.0, M_PI / 2, },
+};
+
/*
* asin(3)
*/
@@ -103,27 +117,24 @@
#endif
}
-ATF_TC(asin_sin);
-ATF_TC_HEAD(asin_sin, tc)
+ATF_TC(asin_inrange);
+ATF_TC_HEAD(asin_inrange, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test asin(sin(x)) == x");
+ atf_tc_set_md_var(tc, "descr", "Test asin(x) for some values");
}
-ATF_TC_BODY(asin_sin, tc)
+ATF_TC_BODY(asin_inrange, tc)
{
#ifndef __vax__
- const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
- const double eps = 1.0e-40;
+ const double eps = 1.0e-15;
double y;
size_t i;
- for (i = 0; i < __arraycount(x); i++) {
-
- y = asin(sin(x[i]));
-
- if (fabs(y - x[i]) > eps)
- atf_tc_fail_nonfatal("asin(sin(%0.03f)) != %0.03f",
- x[i], x[i]);
+ for (i = 0; i < __arraycount(values); i++) {
+ y = asin(values[i].x);
+ if (fabs(y - values[i].y) > eps)
+ atf_tc_fail_nonfatal("asin(%g) != %g",
+ values[i].x, values[i].y);
}
#endif
}
@@ -233,27 +244,25 @@
#endif
}
-ATF_TC(asinf_sinf);
-ATF_TC_HEAD(asinf_sinf, tc)
+ATF_TC(asinf_inrange);
+ATF_TC_HEAD(asinf_inrange, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test asinf(sinf(x)) == x");
+ atf_tc_set_md_var(tc, "descr", "Test asinf(x) for some values");
}
-ATF_TC_BODY(asinf_sinf, tc)
+ATF_TC_BODY(asinf_inrange, tc)
{
#ifndef __vax__
- const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const float eps = 1.0e-6;
+ float x;
float y;
size_t i;
- for (i = 0; i < __arraycount(x); i++) {
-
- y = asinf(sinf(x[i]));
-
- if (fabsf(y - x[i]) > eps)
- atf_tc_fail_nonfatal("asinf(sinf(%0.03f)) != %0.03f",
- x[i], x[i]);
+ for (i = 0; i < __arraycount(values); i++) {
+ x = values[i].x;
+ y = values[i].y;
+ if (fabs(asinf(x) - y) > eps)
+ atf_tc_fail_nonfatal("asinf(%g) != %g", x, y);
}
#endif
}
@@ -299,7 +308,7 @@
ATF_TP_ADD_TC(tp, asin_inf_neg);
ATF_TP_ADD_TC(tp, asin_inf_pos);
ATF_TP_ADD_TC(tp, asin_range);
- ATF_TP_ADD_TC(tp, asin_sin);
+ ATF_TP_ADD_TC(tp, asin_inrange);
ATF_TP_ADD_TC(tp, asin_zero_neg);
ATF_TP_ADD_TC(tp, asin_zero_pos);
@@ -307,7 +316,7 @@
ATF_TP_ADD_TC(tp, asinf_inf_neg);
ATF_TP_ADD_TC(tp, asinf_inf_pos);
ATF_TP_ADD_TC(tp, asinf_range);
- ATF_TP_ADD_TC(tp, asinf_sinf);
+ ATF_TP_ADD_TC(tp, asinf_inrange);
ATF_TP_ADD_TC(tp, asinf_zero_neg);
ATF_TP_ADD_TC(tp, asinf_zero_pos);
diff -r 09ad72e1163d -r a65bb07f47a8 tests/lib/libm/t_atan.c
--- a/tests/lib/libm/t_atan.c Tue Apr 09 11:42:56 2013 +0000
+++ b/tests/lib/libm/t_atan.c Tue Apr 09 12:11:04 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_atan.c,v 1.7 2013/03/21 02:10:52 isaki Exp $ */
+/* $NetBSD: t_atan.c,v 1.8 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -35,6 +35,20 @@
#include <stdlib.h>
#include <string.h>
+static const struct {
+ double x;
+ double y;
+} values[] = {
+ { -100, -1.560796660108231, },
+ { -10, -1.471127674303735, },
+ { -1, -M_PI / 4, },
+ { -0.1, -0.09966865249116204, },
+ { 0.1, 0.09966865249116204, },
+ { 1, M_PI / 4, },
+ { 10, 1.471127674303735, },
+ { 100, 1.560796660108231, },
+};
+
/*
* atan(3)
*/
@@ -88,27 +102,22 @@
#endif
}
-ATF_TC(atan_tan);
-ATF_TC_HEAD(atan_tan, tc)
+ATF_TC(atan_inrange);
+ATF_TC_HEAD(atan_inrange, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test atan(tan(x)) == x");
+ atf_tc_set_md_var(tc, "descr", "Test atan(x) for some values");
}
-ATF_TC_BODY(atan_tan, tc)
+ATF_TC_BODY(atan_inrange, tc)
{
#ifndef __vax__
- const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const double eps = 1.0e-15;
- double y;
size_t i;
Home |
Main Index |
Thread Index |
Old Index