Changeset View
Changeset View
Standalone View
Standalone View
lib/msun/tests/conj_test.c
Show All 25 Lines | |||||||||||||||||||||||||||||
/* | /* | ||||||||||||||||||||||||||||
* Tests for conj{,f,l}() | * Tests for conj{,f,l}() | ||||||||||||||||||||||||||||
*/ | */ | ||||||||||||||||||||||||||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||||||||||||||||||||||||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||||||||||||||||||||||||||
#include <assert.h> | |||||||||||||||||||||||||||||
#include <complex.h> | #include <complex.h> | ||||||||||||||||||||||||||||
#include <fenv.h> | #include <fenv.h> | ||||||||||||||||||||||||||||
#include <math.h> | #include <math.h> | ||||||||||||||||||||||||||||
#include <stdio.h> | #include <stdio.h> | ||||||||||||||||||||||||||||
#include "test-utils.h" | #include "test-utils.h" | ||||||||||||||||||||||||||||
#pragma STDC CX_LIMITED_RANGE OFF | #pragma STDC CX_LIMITED_RANGE OFF | ||||||||||||||||||||||||||||
Show All 22 Lines | static const double tests[] = { | ||||||||||||||||||||||||||||
0.0, -INFINITY, | 0.0, -INFINITY, | ||||||||||||||||||||||||||||
INFINITY, 0.0, | INFINITY, 0.0, | ||||||||||||||||||||||||||||
NAN, 1.0, | NAN, 1.0, | ||||||||||||||||||||||||||||
1.0, NAN, | 1.0, NAN, | ||||||||||||||||||||||||||||
NAN, NAN, | NAN, NAN, | ||||||||||||||||||||||||||||
-INFINITY, INFINITY, | -INFINITY, INFINITY, | ||||||||||||||||||||||||||||
}; | }; | ||||||||||||||||||||||||||||
int | ATF_TC_WITHOUT_HEAD(main); | ||||||||||||||||||||||||||||
main(void) | ATF_TC_BODY(main, tc) | ||||||||||||||||||||||||||||
{ | { | ||||||||||||||||||||||||||||
static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2; | static const int ntests = sizeof(tests) / sizeof(tests[0]) / 2; | ||||||||||||||||||||||||||||
complex float in; | complex float in; | ||||||||||||||||||||||||||||
complex long double expected; | complex long double expected; | ||||||||||||||||||||||||||||
int i; | int i; | ||||||||||||||||||||||||||||
printf("1..%d\n", ntests * 3); | |||||||||||||||||||||||||||||
for (i = 0; i < ntests; i++) { | for (i = 0; i < ntests; i++) { | ||||||||||||||||||||||||||||
__real__ expected = __real__ in = tests[2 * i]; | __real__ expected = __real__ in = tests[2 * i]; | ||||||||||||||||||||||||||||
__imag__ in = tests[2 * i + 1]; | __imag__ in = tests[2 * i + 1]; | ||||||||||||||||||||||||||||
__imag__ expected = -cimag(in); | __imag__ expected = -cimag(in); | ||||||||||||||||||||||||||||
assert(fpequal(libcrealf(in), __real__ in)); | ATF_REQUIRE(fpequal(libcrealf(in), __real__ in)); | ||||||||||||||||||||||||||||
assert(fpequal(libcreal(in), __real__ in)); | ATF_REQUIRE(fpequal(libcreal(in), __real__ in)); | ||||||||||||||||||||||||||||
assert(fpequal(libcreall(in), __real__ in)); | ATF_REQUIRE(fpequal(libcreall(in), __real__ in)); | ||||||||||||||||||||||||||||
assert(fpequal(libcimagf(in), __imag__ in)); | ATF_REQUIRE(fpequal(libcimagf(in), __imag__ in)); | ||||||||||||||||||||||||||||
assert(fpequal(libcimag(in), __imag__ in)); | ATF_REQUIRE(fpequal(libcimag(in), __imag__ in)); | ||||||||||||||||||||||||||||
assert(fpequal(libcimagl(in), __imag__ in)); | ATF_REQUIRE(fpequal(libcimagl(in), __imag__ in)); | ||||||||||||||||||||||||||||
ngie: `assert`s should be converted into `ATF_REQUIRE_MSG(..)` in cases like this: not doing so could… | |||||||||||||||||||||||||||||
feclearexcept(FE_ALL_EXCEPT); | ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
if (!cfpequal(libconjf(in), expected)) { | ATF_REQUIRE_MSG( | ||||||||||||||||||||||||||||
printf("not ok %d\t# conjf(%#.2g + %#.2gI): " | cfpequal(libconjf(in), expected), | ||||||||||||||||||||||||||||
"wrong value\n", | "conjf(%#.2g + %#.2gI): wrong value", creal(in), cimag(in) | ||||||||||||||||||||||||||||
3 * i + 1, creal(in), cimag(in)); | ); | ||||||||||||||||||||||||||||
} else if (fetestexcept(FE_ALL_EXCEPT)) { | ATF_REQUIRE_EQ_MSG(0, fetestexcept(FE_ALL_EXCEPT), | ||||||||||||||||||||||||||||
printf("not ok %d\t# conjf(%#.2g + %#.2gI): " | "conj(%#.2g + %#.2gI): threw an exception: %#x", creal(in), | ||||||||||||||||||||||||||||
"threw an exception\n", | cimag(in), fetestexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
Done Inline ActionsThis needs to be changed into 2 asserts: ATF_REQUIRE_MSG( cfpequal(libconjf(in), expected), "conjf(%#.2g + %#.2gI): wrong value", creal(in), cimag(in) ); ATF_REQUIRE_MSG( !fetestexcept(FE_ALL_EXCEPT), "conjf(%#.2g + %#.2gI): threw an exception", creal(in), cimag(in) ); ngie: This needs to be changed into 2 asserts:
```
ATF_REQUIRE_MSG(
cfpequal(libconjf(in)… | |||||||||||||||||||||||||||||
3 * i + 1, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} else { | |||||||||||||||||||||||||||||
printf("ok %d\t\t# conjf(%#.2g + %#.2gI)\n", | |||||||||||||||||||||||||||||
3 * i + 1, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||
feclearexcept(FE_ALL_EXCEPT); | ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
if (!cfpequal(libconj(in), expected)) { | ATF_REQUIRE_MSG(cfpequal(libconj(in), expected), | ||||||||||||||||||||||||||||
printf("not ok %d\t# conj(%#.2g + %#.2gI): " | "conj(%#.2g + %#.2gI): wrong value", creal(in), cimag(in)); | ||||||||||||||||||||||||||||
"wrong value\n", | ATF_REQUIRE_EQ_MSG(0, fetestexcept(FE_ALL_EXCEPT), | ||||||||||||||||||||||||||||
3 * i + 2, creal(in), cimag(in)); | "conj(%#.2g + %#.2gI): threw an exception: %#x", creal(in), | ||||||||||||||||||||||||||||
} else if (fetestexcept(FE_ALL_EXCEPT)) { | cimag(in), fetestexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
Done Inline Actions
Please use ATF_REQUIRE_MSG here. ngie: Please use ATF_REQUIRE_MSG here. | |||||||||||||||||||||||||||||
printf("not ok %d\t# conj(%#.2g + %#.2gI): " | |||||||||||||||||||||||||||||
"threw an exception\n", | |||||||||||||||||||||||||||||
3 * i + 2, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} else { | |||||||||||||||||||||||||||||
printf("ok %d\t\t# conj(%#.2g + %#.2gI)\n", | |||||||||||||||||||||||||||||
3 * i + 2, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} | |||||||||||||||||||||||||||||
feclearexcept(FE_ALL_EXCEPT); | ATF_REQUIRE_EQ(0, feclearexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
if (!cfpequal(libconjl(in), expected)) { | ATF_REQUIRE_MSG(cfpequal(libconjl(in), expected), | ||||||||||||||||||||||||||||
printf("not ok %d\t# conjl(%#.2g + %#.2gI): " | "conjl(%#.2g + %#.2gI): wrong value", creal(in), cimag(in)); | ||||||||||||||||||||||||||||
"wrong value\n", | ATF_REQUIRE_EQ_MSG(0, fetestexcept(FE_ALL_EXCEPT), | ||||||||||||||||||||||||||||
3 * i + 3, creal(in), cimag(in)); | "conjl(%#.2g + %#.2gI): threw an exception: %#x", creal(in), | ||||||||||||||||||||||||||||
} else if (fetestexcept(FE_ALL_EXCEPT)) { | cimag(in), fetestexcept(FE_ALL_EXCEPT)); | ||||||||||||||||||||||||||||
Done Inline Actions
Please use ATF_REQUIRE_MSG instead. ngie: Please use ATF_REQUIRE_MSG instead. | |||||||||||||||||||||||||||||
Done Inline ActionsThanks, also looking at the this should have been conjl all along since it's just doing the same thing again. arichardson: Thanks, also looking at the this should have been conjl all along since it's just doing the… | |||||||||||||||||||||||||||||
printf("not ok %d\t# conjl(%#.2g + %#.2gI): " | |||||||||||||||||||||||||||||
"threw an exception\n", | |||||||||||||||||||||||||||||
3 * i + 3, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} else { | |||||||||||||||||||||||||||||
printf("ok %d\t\t# conjl(%#.2g + %#.2gI)\n", | |||||||||||||||||||||||||||||
3 * i + 3, creal(in), cimag(in)); | |||||||||||||||||||||||||||||
} | } | ||||||||||||||||||||||||||||
} | } | ||||||||||||||||||||||||||||
return (0); | ATF_TP_ADD_TCS(tp) | ||||||||||||||||||||||||||||
{ | |||||||||||||||||||||||||||||
ATF_TP_ADD_TC(tp, main); | |||||||||||||||||||||||||||||
return (atf_no_error()); | |||||||||||||||||||||||||||||
} | } |
asserts should be converted into ATF_REQUIRE_MSG(..) in cases like this: not doing so could result in non-sensical cascading failures.