2
0
mirror of https://github.com/boostorg/hof.git synced 2026-01-20 16:42:14 +00:00
Files
hof/test/reverse_compress.cpp
2016-01-17 23:16:02 -06:00

79 lines
2.1 KiB
C++

#include <fit/reverse_compress.hpp>
#include "test.hpp"
struct max_f
{
template<class T, class U>
constexpr T operator()(T x, U y) const
{
return x > y ? x : y;
}
};
struct sum_f
{
template<class T, class U>
constexpr T operator()(T x, U y) const
{
return x + y;
}
};
FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::reverse_compress(max_f(), 0)(2, 3, 4, 5) == 5);
FIT_TEST_CHECK(fit::reverse_compress(max_f(), 0)(5, 4, 3, 2) == 5);
FIT_TEST_CHECK(fit::reverse_compress(max_f(), 0)(2, 3, 5, 4) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f(), 0)(2, 3, 4, 5) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f(), 0)(5, 4, 3, 2) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f(), 0)(2, 3, 5, 4) == 5);
}
FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::reverse_compress(max_f(), 0)() == 0);
FIT_TEST_CHECK(fit::reverse_compress(max_f(), 0)(5) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f(), 0)() == 0);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f(), 0)(5) == 5);
}
template<class... Ts>
constexpr auto find_positive_max(Ts... xs) FIT_RETURNS
(
fit::reverse_compress(max_f(), 0)(xs...)
);
FIT_TEST_CASE()
{
FIT_TEST_CHECK(find_positive_max() == 0);
FIT_TEST_CHECK(find_positive_max(5) == 5);
FIT_STATIC_TEST_CHECK(find_positive_max() == 0);
FIT_STATIC_TEST_CHECK(find_positive_max(5) == 5);
}
FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::reverse_compress(max_f())(5) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f())(5) == 5);
}
FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::reverse_compress(max_f())(2, 3, 4, 5) == 5);
FIT_TEST_CHECK(fit::reverse_compress(max_f())(5, 4, 3, 2) == 5);
FIT_TEST_CHECK(fit::reverse_compress(max_f())(2, 3, 5, 4) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f())(2, 3, 4, 5) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f())(5, 4, 3, 2) == 5);
FIT_STATIC_TEST_CHECK(fit::reverse_compress(max_f())(2, 3, 5, 4) == 5);
}
FIT_TEST_CASE()
{
FIT_TEST_CHECK(fit::reverse_compress(sum_f(), std::string())("hello", "-", "world") == "world-hello");
}