77#include < boost/algorithm/clamp.hpp>
88#include < cmath>
99#include < cstdint>
10- #ifdef __cpp_impl_three_way_comparison &&__has_include(<compare>)
10+ #ifdef __cpp_impl_three_way_comparison
11+ #if __has_include(<compare>)
12+ #define BOOST_IS_CLAMPED_TEST_SPACESHIP
13+ #endif
14+ #ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
1115#include < compare>
1216#endif
17+ #endif
1318#include < limits>
1419#include < string>
1520#include < tuple>
@@ -84,11 +89,11 @@ void test_ints() {
8489 BOOST_CHECK_EQUAL ( false , ba::is_clamped ( 0U , 1 , 6 . ));
8590 BOOST_CHECK_EQUAL ( false , ba::is_clamped ( 8U , 1 , 6 . ));
8691
87- short foo = 50 ;
8892 // float->short conversion does not round
89- BOOST_CHECK_EQUAL ( true , ba::is_clamped ( foo , 50.999 , 100 ));
90- BOOST_CHECK_EQUAL ( false , ba::is_clamped ( foo , 51.001 , 100 ));
93+ BOOST_CHECK_EQUAL ( true , ba::is_clamped ( 50 , 50.999 , 100 ));
94+ BOOST_CHECK_EQUAL ( false , ba::is_clamped ( 50 , 51.001 , 100 ));
9195}
96+
9297void test_floats () {
9398 // If floats are IEEE754 certain floats have exact representations.
9499 if (std::numeric_limits<float >::is_iec559) {
@@ -141,6 +146,21 @@ void test_custom() {
141146 BOOST_CHECK_EQUAL ( false , ba::is_clamped ( c7, c1, c6, customLess ));
142147}
143148
149+ void test_point_interval () {
150+ BOOST_CHECK_EQUAL (true , ba::is_clamped (1 , 1 , 1 ));
151+ BOOST_CHECK_EQUAL (false , ba::is_clamped (0 , 1 , 1 ));
152+ BOOST_CHECK_EQUAL (false , ba::is_clamped (2 , 1 , 1 ));
153+ }
154+
155+ void test_first_argument_determines_types () {
156+ // all arguments are int
157+ BOOST_CHECK_EQUAL (true , ba::is_clamped (5 , 5.9 , 6.1 ));
158+ BOOST_CHECK_EQUAL (true , ba::is_clamped (6 , 5.9 , 6.1 ));
159+ // all arguments are double
160+ BOOST_CHECK_EQUAL (false , ba::is_clamped (5.0 , 5.9 , 6.1 ));
161+ BOOST_CHECK_EQUAL (false , ba::is_clamped (6.2 , 5.9 , 6.1 ));
162+ }
163+
144164void test_constexpr () {
145165 #if __cplusplus >= 201402L
146166 {
@@ -167,15 +187,15 @@ void test_constexpr() {
167187}
168188
169189
170- #ifdef __cpp_impl_three_way_comparison &&__has_include(<compare>)
190+ #ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
171191struct custom_with_spaceship {
172192 int v;
173193 auto operator <=>(const custom_with_spaceship&) const = default ;
174194};
175195#endif
176196
177197void test_spaceship () {
178- #ifdef __cpp_impl_three_way_comparison &&__has_include(<compare>)
198+ #ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
179199 // Inside the range, equal to the endpoints, and outside the endpoints.
180200 const custom_with_spaceship c0 (0 );
181201 const custom_with_spaceship c1 (1 );
@@ -202,6 +222,8 @@ BOOST_AUTO_TEST_CASE(test_main) {
202222 test_floats ();
203223 test_std_string ();
204224 test_custom ();
225+ test_point_interval ();
226+ test_first_argument_determines_types ();
205227 test_constexpr ();
206228 test_spaceship ();
207229}
0 commit comments