|
18 | 18 | #include <algorithm>
|
19 | 19 | #include <cassert>
|
20 | 20 | #include <iterator>
|
| 21 | +#include <limits> |
21 | 22 | #include <random>
|
22 | 23 | #include <vector>
|
23 | 24 |
|
@@ -68,6 +69,13 @@ TEST_CONSTEXPR_CXX26 std::vector<T> generate_sawtooth(int N, int M) {
|
68 | 69 | if (++x == M)
|
69 | 70 | x = 0;
|
70 | 71 | }
|
| 72 | + |
| 73 | + if (std::is_signed<T>::value) { |
| 74 | + for (auto& a : v) { |
| 75 | + a -= (M / 2); |
| 76 | + } |
| 77 | + } |
| 78 | + |
71 | 79 | return v;
|
72 | 80 | }
|
73 | 81 |
|
@@ -193,12 +201,38 @@ TEST_CONSTEXPR_CXX26 bool test() {
|
193 | 201 | return true;
|
194 | 202 | }
|
195 | 203 |
|
| 204 | +template <class T> |
| 205 | +bool test_floating_special_values() { |
| 206 | + static_assert(std::is_floating_point<T>::value, ""); |
| 207 | + |
| 208 | + auto v = generate_sawtooth<T>(1024, 512); |
| 209 | + v.insert(v.end(), 256, static_cast<T>(0.0)); |
| 210 | + v.insert(v.end(), 256, static_cast<T>(-0.0)); |
| 211 | + v.insert(v.end(), 256, std::numeric_limits<T>::infinity()); |
| 212 | + v.insert(v.end(), 256, -std::numeric_limits<T>::infinity()); |
| 213 | + |
| 214 | + std::mt19937 randomness; |
| 215 | + std::shuffle(v.begin(), v.end(), randomness); |
| 216 | + |
| 217 | + std::stable_sort(v.begin(), v.end()); |
| 218 | + assert(std::is_sorted(v.begin(), v.end())); |
| 219 | + |
| 220 | + return true; |
| 221 | +} |
| 222 | + |
| 223 | +template <class T> |
| 224 | +bool test_floating() { |
| 225 | + return test<T>() && test_floating_special_values<T>(); |
| 226 | +} |
| 227 | + |
196 | 228 | int main(int, char**) {
|
197 | 229 | test<int>();
|
198 |
| - test<float>(); |
| 230 | + test_floating<float>(); |
| 231 | + test_floating<double>(); |
199 | 232 | #if TEST_STD_VER >= 26
|
200 | 233 | static_assert(test<int>());
|
201 | 234 | static_assert(test<float>());
|
| 235 | + static_assert(test<double>()); |
202 | 236 | // test constexprness of radix sort branch
|
203 | 237 | static_assert(test<char>());
|
204 | 238 | #endif
|
|
0 commit comments