Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup tests to be friendlier to modules #3034

Merged
merged 7 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/std/include/parallel_algorithms_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#pragma once
#include <algorithm>
#include <cstddef>
#include <limits>
#include <thread>

#ifdef EXHAUSTIVE
const size_t max_parallel_test_case_n = 4096;
// the number of linear steps a test case that is quadratic should attempt:
const size_t quadratic_complexity_case_limit = SIZE_MAX;
const size_t quadratic_complexity_case_limit = std::numeric_limits<std::size_t>::max();
#else // ^^^ EXHAUSTIVE ^^^ // vvv !EXHAUSTIVE vvv
// The constant 32 comes from std::_Oversubscription_multiplier
const size_t max_parallel_test_case_n = std::max(4u, std::thread::hardware_concurrency() * 32) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <unordered_set>
#include <utility>

using namespace std;

constexpr auto size_max = numeric_limits<size_t>::max();

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

void assert_is_pow2(const size_t value) {
Expand Down Expand Up @@ -120,8 +122,8 @@ void test_LWG_2156() {
x.emplace(0);
assert(x.bucket_count() == afterRehashBuckets);

assert_throws<length_error>([&] { x.rehash(SIZE_MAX); });
assert_throws<length_error>([&] { x.rehash(SIZE_MAX / 2); });
assert_throws<length_error>([&] { x.rehash(size_max); });
assert_throws<length_error>([&] { x.rehash(size_max / 2); });

#ifndef _WIN64
// make it so rehash can't meet its postcondition, even when not asking for more buckets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
#include <cassert>
#include <cstdint>
#include <execution>
#include <limits>
#include <random>
#include <vector>

using namespace std;
using namespace std::execution;

constexpr auto int16_min = numeric_limits<int16_t>::min();
constexpr auto int16_max = numeric_limits<int16_t>::max();
constexpr auto int32_min = numeric_limits<int32_t>::min();
constexpr auto int32_max = numeric_limits<int32_t>::max();
constexpr auto int64_min = numeric_limits<int64_t>::min();
constexpr auto int64_max = numeric_limits<int64_t>::max();
constexpr auto uint16_max = numeric_limits<uint16_t>::max();
constexpr auto uint32_max = numeric_limits<uint32_t>::max();
constexpr auto uint64_max = numeric_limits<uint64_t>::max();

constexpr uint32_t N = 500'000;

template <typename URNG, typename T, T A, T B>
Expand All @@ -31,33 +42,33 @@ void add_tests(vector<fp_t>& tests) {
// Test DevDiv-83370 "uniform_int_distribution isn't uniform".
tests.insert(
tests.end(), {
microtest<URNG, int16_t, INT16_MIN, INT16_MAX>,
microtest<URNG, int16_t, INT16_MIN + 1, INT16_MAX>,
microtest<URNG, int16_t, INT16_MIN, INT16_MAX - 1>,
microtest<URNG, int16_t, INT16_MIN + 2, INT16_MAX - 3>,
microtest<URNG, int16_t, int16_min, int16_max>,
microtest<URNG, int16_t, int16_min + 1, int16_max>,
microtest<URNG, int16_t, int16_min, int16_max - 1>,
microtest<URNG, int16_t, int16_min + 2, int16_max - 3>,
microtest<URNG, int16_t, -4, 4>,
microtest<URNG, int16_t, 11, 22>,
microtest<URNG, int16_t, -44, -33>,
microtest<URNG, int16_t, 5, 6>,
microtest<URNG, int16_t, -7, -7>,

microtest<URNG, uint16_t, 0, UINT16_MAX>,
microtest<URNG, uint16_t, 1, UINT16_MAX>,
microtest<URNG, uint16_t, 0, UINT16_MAX - 1>,
microtest<URNG, uint16_t, 2, UINT16_MAX - 3>,
microtest<URNG, uint16_t, 0, uint16_max>,
microtest<URNG, uint16_t, 1, uint16_max>,
microtest<URNG, uint16_t, 0, uint16_max - 1>,
microtest<URNG, uint16_t, 2, uint16_max - 3>,
microtest<URNG, uint16_t, 123, 456>,
microtest<URNG, uint16_t, 1000, 1001>,
microtest<URNG, uint16_t, 777, 777>,

microtest<URNG, int32_t, INT32_MIN, INT32_MAX>,
microtest<URNG, int32_t, INT32_MIN + 2, INT32_MAX - 3>,
microtest<URNG, uint32_t, 0, UINT32_MAX>,
microtest<URNG, uint32_t, 2, UINT32_MAX - 3>,
microtest<URNG, int64_t, INT64_MIN, INT64_MAX>,
microtest<URNG, int64_t, INT64_MIN + 2, INT64_MAX - 3>,
microtest<URNG, uint64_t, 0, UINT64_MAX>, // Test DDB-181509 "TR1 VC9 SP1: Infinite loop in
microtest<URNG, int32_t, int32_min, int32_max>,
microtest<URNG, int32_t, int32_min + 2, int32_max - 3>,
microtest<URNG, uint32_t, 0, uint32_max>,
microtest<URNG, uint32_t, 2, uint32_max - 3>,
microtest<URNG, int64_t, int64_min, int64_max>,
microtest<URNG, int64_t, int64_min + 2, int64_max - 3>,
microtest<URNG, uint64_t, 0, uint64_max>, // Test DDB-181509 "TR1 VC9 SP1: Infinite loop in
// uniform_int<unsigned long long>::_Eval()".
microtest<URNG, uint64_t, 2, UINT64_MAX - 3>,
microtest<URNG, uint64_t, 2, uint64_max - 3>,

microtest<URNG, int32_t, -4, 4>,
microtest<URNG, int32_t, 11, 22>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <algorithm>
#include <cassert>
#include <climits>
#include <iterator>
#include <limits>
#include <list>
Expand All @@ -26,6 +25,9 @@

using namespace std;

constexpr auto long_min = numeric_limits<long>::min();
constexpr auto long_max = numeric_limits<long>::max();

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

struct Cat {
Expand Down Expand Up @@ -386,13 +388,13 @@ int main() {

// No longer integral promotions, still repeat the applicable part once to be sure

const long sl[] = {LONG_MIN, LONG_MIN + 1, LONG_MIN + 2, -2, -1, 0, 1, 2, LONG_MAX - 2, LONG_MAX - 1, LONG_MAX};
const long sl[] = {long_min, long_min + 1, long_min + 2, -2, -1, 0, 1, 2, long_max - 2, long_max - 1, long_max};

STATIC_ASSERT(static_cast<long>(-1) != static_cast<unsigned short>(0xFFFF));
STATIC_ASSERT(static_cast<long>(-1) == 0xFFFFFFFFUL);
STATIC_ASSERT(static_cast<long>(-2) == 0xFFFFFFFEUL);
STATIC_ASSERT(static_cast<long>(LONG_MIN + 1) == 0x80000001UL);
STATIC_ASSERT(static_cast<long>(LONG_MIN) == 0x80000000UL);
STATIC_ASSERT(static_cast<long>(long_min + 1) == 0x80000001UL);
STATIC_ASSERT(static_cast<long>(long_min) == 0x80000000UL);

assert(find(begin(sl), end(sl), static_cast<unsigned short>(0xFFFF)) == end(sl));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
#include <cassert>
#include <chrono>
#include <cstdint>
#include <limits>

using namespace std;
using namespace std::chrono;

constexpr auto int64_min = numeric_limits<int64_t>::min();
constexpr auto int64_max = numeric_limits<int64_t>::max();

void test(const system_clock::time_point& tp, const long long t1, const long long t2) {
assert(tp.time_since_epoch().count() == t1);
assert(system_clock::to_time_t(tp) == t2);
Expand All @@ -25,8 +29,8 @@ int main() {
test(system_clock::time_point(system_clock::duration(13595108501597374LL)), 13595108501597374LL, 1359510850LL);

test(system_clock::time_point::min(),
/* -9223372036854775808LL */ INT64_MIN, -922337203685LL);
/* -9223372036854775808LL */ int64_min, -922337203685LL);

test(system_clock::time_point::max(),
/* 9223372036854775807LL */ INT64_MAX, 922337203685LL);
/* 9223372036854775807LL */ int64_max, 922337203685LL);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <new>

#if _HAS_CXX17 && !defined(_M_CEE)
Expand All @@ -20,10 +21,12 @@

using namespace std;

constexpr auto size_max = numeric_limits<size_t>::max();

#pragma warning(disable : 28251) // Inconsistent annotation for 'new': this instance has no annotations.

constexpr size_t prohibit_attempts_to_allocate = SIZE_MAX; // extension provided by our STL
constexpr size_t max_allocate = SIZE_MAX - 1;
constexpr size_t prohibit_attempts_to_allocate = size_max; // extension provided by our STL
constexpr size_t max_allocate = size_max - 1;
size_t g_max_memory = max_allocate;

void* operator new(size_t size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@
// diverse floating point values (both single and double precision).

#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <ios>
#include <limits>
#include <sstream>

#include <floating_point_test_cases.hpp>

constexpr auto int64_max = std::numeric_limits<std::int64_t>::max();
constexpr auto uint64_max = std::numeric_limits<std::uint64_t>::max();

constexpr auto flt_min_exp = std::numeric_limits<float>::min_exponent;
constexpr auto flt_max_exp = std::numeric_limits<float>::max_exponent;
constexpr auto dbl_min_exp = std::numeric_limits<double>::min_exponent;
constexpr auto dbl_max_exp = std::numeric_limits<double>::max_exponent;

constexpr auto flt_min_10_exp = std::numeric_limits<float>::min_exponent10;
constexpr auto flt_max_10_exp = std::numeric_limits<float>::max_exponent10;
constexpr auto dbl_min_10_exp = std::numeric_limits<double>::min_exponent10;
constexpr auto dbl_max_10_exp = std::numeric_limits<double>::max_exponent10;

template <typename FloatingType>
static FloatingType parse_as(char const*);

Expand Down Expand Up @@ -167,41 +180,41 @@ int main() {
}

// Verify all representable powers of two and nearby values:
for (int32_t i = FLT_MIN_EXP; i != FLT_MAX_EXP; ++i) {
for (int32_t i = flt_min_exp; i != flt_max_exp; ++i) {
auto const f = powf(2.0f, static_cast<float>(i));
verify_round_trip(from_bits(as_bits(f) - 1));
verify_round_trip(f);
verify_round_trip(from_bits(as_bits(f) + 1));
}

for (int32_t i = DBL_MIN_EXP; i != DBL_MAX_EXP; ++i) {
for (int32_t i = dbl_min_exp; i != dbl_max_exp; ++i) {
auto const f = pow(2.0, static_cast<double>(i));
verify_round_trip(from_bits(as_bits(f) - 1));
verify_round_trip(f);
verify_round_trip(from_bits(as_bits(f) + 1));
}

// Verify all representable powers of ten and nearby values:
for (int32_t i = FLT_MIN_10_EXP; i <= FLT_MAX_10_EXP; ++i) {
for (int32_t i = flt_min_10_exp; i <= flt_max_10_exp; ++i) {
auto const f = powf(10.0f, static_cast<float>(i));
verify_round_trip(from_bits(as_bits(f) - 1));
verify_round_trip(f);
verify_round_trip(from_bits(as_bits(f) + 1));
}

for (int32_t i = DBL_MIN_10_EXP; i <= DBL_MAX_10_EXP; ++i) {
for (int32_t i = dbl_min_10_exp; i <= dbl_max_10_exp; ++i) {
auto const f = pow(10.0, static_cast<double>(i));
verify_round_trip(from_bits(as_bits(f) - 1));
verify_round_trip(f);
verify_round_trip(from_bits(as_bits(f) + 1));
}

// Verify a few large integer values:
verify_round_trip(static_cast<float>(INT64_MAX));
verify_round_trip(static_cast<float>(UINT64_MAX));
verify_round_trip(static_cast<float>(int64_max));
verify_round_trip(static_cast<float>(uint64_max));

verify_round_trip(static_cast<double>(INT64_MAX));
verify_round_trip(static_cast<double>(UINT64_MAX));
verify_round_trip(static_cast<double>(int64_max));
verify_round_trip(static_cast<double>(uint64_max));

// https://www.exploringbinary.com/nondeterministic-floating-point-conversions-in-java/
parse_and_verify_exact_bits_hex<double>("0x0.0000008p-1022", 0x0000000008000000ULL);
Expand Down
17 changes: 11 additions & 6 deletions tests/std/tests/Dev11_1074023_constexpr/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ using namespace std;
using namespace std::chrono;
namespace RC = std::regex_constants;

constexpr auto int32_min = numeric_limits<int32_t>::min();
constexpr auto int32_max = numeric_limits<int32_t>::max();
constexpr auto int64_min = numeric_limits<int64_t>::min();
constexpr auto int64_max = numeric_limits<int64_t>::max();

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

constexpr initializer_list<int> il;
Expand Down Expand Up @@ -445,8 +450,8 @@ STATIC_ASSERT(ratio<252, 105>::num == 12);
STATIC_ASSERT(ratio<252, 105>::den == 5);

STATIC_ASSERT(duration_values<int32_t>::zero() == 0);
STATIC_ASSERT(duration_values<int32_t>::min() == INT32_MIN);
STATIC_ASSERT(duration_values<int32_t>::max() == INT32_MAX);
STATIC_ASSERT(duration_values<int32_t>::min() == int32_min);
STATIC_ASSERT(duration_values<int32_t>::max() == int32_max);

constexpr seconds d1{};
STATIC_ASSERT(d1.count() == 0);
Expand All @@ -464,8 +469,8 @@ constexpr milliseconds d5(d4);
STATIC_ASSERT(d5.count() == 47000);

STATIC_ASSERT(duration<int64_t>::zero().count() == 0);
STATIC_ASSERT(duration<int64_t>::min().count() == INT64_MIN);
STATIC_ASSERT(duration<int64_t>::max().count() == INT64_MAX);
STATIC_ASSERT(duration<int64_t>::min().count() == int64_min);
STATIC_ASSERT(duration<int64_t>::max().count() == int64_max);

constexpr seconds d6(1700);
constexpr seconds d7(29);
Expand Down Expand Up @@ -538,8 +543,8 @@ constexpr time_point<system_clock, seconds> tp2(16s);
STATIC_ASSERT(tp2.time_since_epoch().count() == 16);
constexpr time_point<system_clock, milliseconds> tp3(tp2);
STATIC_ASSERT(tp3.time_since_epoch().count() == 16000);
STATIC_ASSERT(time_point<system_clock, duration<int32_t>>::min().time_since_epoch().count() == INT32_MIN);
STATIC_ASSERT(time_point<system_clock, duration<int32_t>>::max().time_since_epoch().count() == INT32_MAX);
STATIC_ASSERT(time_point<system_clock, duration<int32_t>>::min().time_since_epoch().count() == int32_min);
STATIC_ASSERT(time_point<system_clock, duration<int32_t>>::max().time_since_epoch().count() == int32_max);

constexpr time_point<system_clock, seconds> tp4(1000s);
constexpr time_point<system_clock, seconds> tp5(729s);
Expand Down
Loading