1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/* Copyright 2017-2021 PaGMO development team
This file is part of the PaGMO library.
The PaGMO library is free software; you can redistribute it and/or modify
it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any
later version.
or both in parallel, as here.
The PaGMO library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the PaGMO library. If not,
see https://www.gnu.org/licenses/. */
#define BOOST_TEST_MODULE custom_comparisons_test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <limits>
#include <stdexcept>
#include <tuple>
#include <pagmo/detail/custom_comparisons.hpp>
#include <pagmo/io.hpp>
#include <pagmo/types.hpp>
using namespace pagmo;
BOOST_AUTO_TEST_CASE(less_than_f_test)
{
auto a_nan = std::nan("");
auto a_big_double = 1e4;
auto a_small_double = -1e4;
// Test all branches on T=double
BOOST_CHECK((detail::less_than_f(a_nan, a_big_double) == false));
BOOST_CHECK((detail::less_than_f<double, true>(a_nan, a_big_double) == false));
BOOST_CHECK((detail::less_than_f<double, false>(a_nan, a_big_double) == true));
BOOST_CHECK((detail::less_than_f(a_nan, a_nan) == false));
BOOST_CHECK((detail::less_than_f<double, true>(a_nan, a_nan) == false));
BOOST_CHECK((detail::less_than_f<double, false>(a_nan, a_nan) == false));
BOOST_CHECK((detail::less_than_f(a_big_double, a_nan) == true));
BOOST_CHECK((detail::less_than_f<double, true>(a_big_double, a_nan) == true));
BOOST_CHECK((detail::less_than_f<double, false>(a_big_double, a_nan) == false));
BOOST_CHECK((detail::less_than_f(a_small_double, a_big_double) == true));
BOOST_CHECK((detail::less_than_f<double, true>(a_small_double, a_big_double) == true));
BOOST_CHECK((detail::less_than_f<double, false>(a_small_double, a_big_double) == true));
BOOST_CHECK((detail::less_than_f(a_big_double, a_small_double) == false));
BOOST_CHECK((detail::less_than_f<double, true>(a_big_double, a_small_double) == false));
BOOST_CHECK((detail::less_than_f<double, false>(a_big_double, a_small_double) == false));
}
BOOST_AUTO_TEST_CASE(greater_than_f_test)
{
auto a_nan = std::nan("");
auto a_big_double = 1e4;
auto a_small_double = -1e4;
// Test all branches on T=double
BOOST_CHECK((detail::greater_than_f(a_nan, a_big_double) == true));
BOOST_CHECK((detail::greater_than_f<double, true>(a_nan, a_big_double) == true));
BOOST_CHECK((detail::greater_than_f<double, false>(a_nan, a_big_double) == false));
BOOST_CHECK((detail::greater_than_f(a_nan, a_nan) == false));
BOOST_CHECK((detail::greater_than_f<double, true>(a_nan, a_nan) == false));
BOOST_CHECK((detail::greater_than_f<double, false>(a_nan, a_nan) == false));
BOOST_CHECK((detail::greater_than_f(a_big_double, a_nan) == false));
BOOST_CHECK((detail::greater_than_f<double, true>(a_big_double, a_nan) == false));
BOOST_CHECK((detail::greater_than_f<double, false>(a_big_double, a_nan) == true));
BOOST_CHECK((detail::greater_than_f(a_small_double, a_big_double) == false));
BOOST_CHECK((detail::greater_than_f<double, true>(a_small_double, a_big_double) == false));
BOOST_CHECK((detail::greater_than_f<double, false>(a_small_double, a_big_double) == false));
BOOST_CHECK((detail::greater_than_f(a_big_double, a_small_double) == true));
BOOST_CHECK((detail::greater_than_f<double, true>(a_big_double, a_small_double) == true));
BOOST_CHECK((detail::greater_than_f<double, false>(a_big_double, a_small_double) == true));
}
BOOST_AUTO_TEST_CASE(equal_to_f_test)
{
auto a_nan = std::nan("");
auto a_double = 123.456;
// Test all branches on T=double
BOOST_CHECK((detail::equal_to_f(a_nan, a_double) == false));
BOOST_CHECK((detail::equal_to_f<double>(a_nan, a_double) == false));
BOOST_CHECK((detail::equal_to_f(a_nan, a_nan) == true));
BOOST_CHECK((detail::equal_to_f<double>(a_nan, a_nan) == true));
BOOST_CHECK((detail::equal_to_f(a_double, a_double) == true));
BOOST_CHECK((detail::equal_to_f<double>(a_double, a_double) == true));
BOOST_CHECK((detail::equal_to_f(a_double, a_nan) == false));
BOOST_CHECK((detail::equal_to_f<double>(a_double, a_nan) == false));
}
BOOST_AUTO_TEST_CASE(equal_to_vf_test)
{
auto a_nan = std::nan("");
vector_double v1 = {1., 2., 3., 4.};
vector_double v2 = {1., 2., 3., 4., 5.};
vector_double v3 = {1., 2., 3.1, 4.};
vector_double v4 = {1., a_nan, 3.1, 4.};
vector_double v5 = {1., a_nan, 3.1, 4.};
vector_double v6 = {1., a_nan, a_nan, 4.};
vector_double v7 = {1., 2.1, 3.1, 4.};
// Test all branches on T=double
BOOST_CHECK((detail::equal_to_vf<double>()(v1, v2) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v1, v3) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v3, v4) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v4, v5) == true));
BOOST_CHECK((detail::equal_to_vf<double>()(v4, v6) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v3, v6) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v3, v6) == false));
BOOST_CHECK((detail::equal_to_vf<double>()(v3, v6) == false));
}
BOOST_AUTO_TEST_CASE(hash_vf_test)
{
auto a_nan = std::nan("");
vector_double v1 = {1., a_nan, 3., 4.};
vector_double v2 = {1., 2., 3., 4.};
vector_double v3 = {1., a_nan, 3., 4.};
BOOST_CHECK((detail::hash_vf<double>()(v1) != detail::hash_vf<double>()(v2)));
BOOST_CHECK((detail::hash_vf<double>()(v3) == detail::hash_vf<double>()(v1)));
}
|