[libcxx-commits] [PATCH] D60350: General abs tests
Eric Fiselier via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 5 17:51:08 PDT 2019
FYI I have patches to fix abs in flight. you may want to hold off for now
On Fri., Apr. 5, 2019, 8:47 p.m. Zoe Carver via Phabricator, <
reviews at reviews.llvm.org> wrote:
> zoecarver created this revision.
> zoecarver added reviewers: mclow.lists, EricWF.
> Herald added subscribers: libcxx-commits, ldionne.
>
> **Why?**
>
> 1. Because there was a lack of `abs` tests
> 2. Because these tests make it very clear what `abs` declarations are where
>
>
> Repository:
> rCXX libc++
>
> https://reviews.llvm.org/D60350
>
> Files:
> test/std/numerics/numerics.abs/abs_tests.h
> test/std/numerics/numerics.abs/cinttypes.pass.cpp
> test/std/numerics/numerics.abs/cmath.pass.cpp
> test/std/numerics/numerics.abs/cstdlib.pass.cpp
> test/std/numerics/numerics.abs/stdlib.h.pass.cpp
>
>
> Index: test/std/numerics/numerics.abs/stdlib.h.pass.cpp
> ===================================================================
> --- /dev/null
> +++ test/std/numerics/numerics.abs/stdlib.h.pass.cpp
> @@ -0,0 +1,9 @@
> +#include "abs_tests.h"
> +
> +#include <stdlib.h>
> +
> +int main()
> +{
> + general_test<long, long>(abs);
> + general_test<long long, long long>(abs);
> +}
> \ No newline at end of file
> Index: test/std/numerics/numerics.abs/cstdlib.pass.cpp
> ===================================================================
> --- /dev/null
> +++ test/std/numerics/numerics.abs/cstdlib.pass.cpp
> @@ -0,0 +1,13 @@
> +#include "abs_tests.h"
> +
> +#include <cstdlib>
> +
> +int main()
> +{
> + general_test<int, int>(std::abs);
> + general_test<long, long>(std::abs);
> + general_test<long long, long long>(std::abs);
> +
> + general_test<long, long>(std::labs);
> + general_test<long long, long long>(std::llabs);
> +}
> \ No newline at end of file
> Index: test/std/numerics/numerics.abs/cmath.pass.cpp
> ===================================================================
> --- /dev/null
> +++ test/std/numerics/numerics.abs/cmath.pass.cpp
> @@ -0,0 +1,13 @@
> +#include "abs_tests.h"
> +
> +#include <cmath>
> +
> +int main()
> +{
> + general_test<float, float>(std::abs);
> + general_test<float, float>(std::fabs);
> + general_test<float, float>(std::fabsf);
> + general_test<double, double>(std::fabs);
> + general_test<long double, long double>(std::fabs);
> + general_test<long double, long double>(std::fabsl);
> +}
> Index: test/std/numerics/numerics.abs/cinttypes.pass.cpp
> ===================================================================
> --- /dev/null
> +++ test/std/numerics/numerics.abs/cinttypes.pass.cpp
> @@ -0,0 +1,9 @@
> +#include "abs_tests.h"
> +
> +#include <cinttypes>
> +
> +int main()
> +{
> + // general_test<std::intmax_t, std::intmax_t>(std::abs);
> + general_test<std::intmax_t, std::intmax_t>(std::imaxabs);
> +}
> Index: test/std/numerics/numerics.abs/abs_tests.h
> ===================================================================
> --- /dev/null
> +++ test/std/numerics/numerics.abs/abs_tests.h
> @@ -0,0 +1,16 @@
> +#include <test_macros.h>
> +#include <cassert>
> +
> +template<class In, class Out>
> +void general_test(Out f(In))
> +{
> + for (In i = -50; i < 50; ++i)
> + {
> + auto res = f(i);
> + ASSERT_SAME_TYPE(decltype(res), Out);
> + if (i > 0)
> + assert(res == i);
> + else
> + assert(res == i - (i * 2));
> + }
> +}
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190405/9af7ddd7/attachment.html>
More information about the libcxx-commits
mailing list