TTS v4.1.0
The Tiny Test System
Loading...
Searching...
No Matches

Generators of the values of the test cases and the range checks. More...

Classes

struct  tts::as_integer< G >
 Adapts a generator to produce unsigned integer values. More...
struct  tts::as_signed_integer< G >
 Adapts a generator to produce signed integer values. More...
struct  tts::between< T, U >
 Generates values linearly spaced between two bounds. More...
struct  tts::is_randoms< G >
 Detects tts::randoms and the classes derived from it. More...
struct  tts::limits_set< T >
 Holds the limits and special values of a type T. More...
struct  tts::logicals< T, U >
 Generates boolean values in a regular pattern. More...
struct  tts::ramp< T, U >
 Generates a ramp of values. More...
struct  tts::random_bits
 Generates random bit patterns. More...
struct  tts::random_shift
 Produces valid shift amounts for the target type. More...
struct  tts::randoms< Mx, Mn >
 Generates random values between two bounds. More...
struct  tts::reverse_ramp< T, U >
 Generates a ramp of values read backward. More...
struct  tts::value< T >
 Generates the same value at every call. More...

Functions

template<typename T>
auto limits (tts::type< T >)
 Returns the limits and special values of a type T.
constexpr tts_implementation_defined tts::sample (std::uint64_t n)
 Generates a given number of values spread over a type or a range.
template<typename T>
constexpr tts_implementation_defined tts::sample (T lo, T hi, std::uint64_t n)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Variables

template<typename G>
constexpr bool tts::is_randoms_v = is_randoms<std::remove_cvref_t<G>>::value
 Value alias for tts::is_randoms, indifferent to references and cv-qualifiers.
constexpr tts_implementation_defined tts::sweep = {}
 Generates every value of a type, or of a range.

Function Documentation

◆ limits()

template<typename T>
auto limits ( tts::type< T > )
related

Returns the limits and special values of a type T.

Template Parameters
TType for which to provide limits
Returns
The tts::limits_set of T.

◆ sample()

tts_implementation_defined tts::sample ( std::uint64_t n)
constexpr

#include <tts/engine/generator.hpp>

Generates a given number of values spread over a type or a range.

Produces n values of an argument of a TTS_ULP_RANGE_CHECK, and never NaN.

  • tts::sample(n) spreads its values over the whole type.
  • tts::sample(lo, hi, n) spreads its values over [lo, hi], its bounds given in either order.

The values are the two bounds and one value per slice of equal width in the ranks of tts::enumeration. The sample thus holds about the same number of values in each binade of a floating-point type, the subnormals of each sign counting as one binade. A range over many binades of small magnitude, such as [-700, 700] in double, has most of its values below 1 in magnitude. If n is 1, the sample holds the lower bound alone. A sample of at least as many values as its range holds gives each value once, as tts::sweep does.

The position of a value within its slice comes from its index and from a value drawn from the generator of the run when the check starts, so each run checks other values, and --seed repeats those of a run.

If n is 0, the check makes no call and records no check, so a case without another check is reported as invalid.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Check two functions over values spread over a range")
{
auto half = [](float x) { return x / 2; };
auto scaled = [](float x) { return x * 0.5f; };
// 4096 floats from -1 to 1: the bounds and about the same number of values in every binade
TTS_ULP_RANGE_CHECK(tts::sample(-1.f, 1.f, 4096), float, float, half, scaled, 0.);
auto twice = [](double x) { return x * 2; };
auto added = [](double x) { return x + x; };
// 2^20 doubles spread over the whole type, which holds too many values for a sweep
TTS_ULP_RANGE_CHECK(tts::sample(1 << 20), double, double, twice, added, 0.);
};

Variable Documentation

◆ sweep

tts_implementation_defined tts::sweep = {}
inlineconstexpr

#include <tts/engine/generator.hpp>

Generates every value of a type, or of a range.

Produces every value of an argument of a TTS_ULP_RANGE_CHECK, NaN excluded since it has no rank in tts::enumeration.

  • tts::sweep covers the whole type, from -inf to +inf for a floating-point type.
  • tts::sweep(lo, hi) covers every value of [lo, hi], its bounds given in either order.

A sweep makes 65536 calls over two std::uint8_t and 4278190082 over a float. If the number of calls exceeds the largest std::size_t, as over two double, the check fails without running, and tts::sample can run such a check on n values per argument.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <cmath>
#include <cstdint>
TTS_CASE("Check two functions over every value of a type or a range")
{
auto halve_ref = [](std::int16_t x) { return static_cast<std::int16_t>(std::floor(x / 2.)); };
auto halve_new = [](std::int16_t x) { return static_cast<std::int16_t>(x >> 1); };
// Each of the 65536 values of std::int16_t
TTS_ULP_RANGE_CHECK(tts::sweep, std::int16_t, std::int16_t, halve_ref, halve_new, 0.);
auto half = [](float x) { return x / 2; };
auto scaled = [](float x) { return x * 0.5f; };
// Each float from 1 to 2, 8388609 values
TTS_ULP_RANGE_CHECK(tts::sweep(1.f, 2.f), float, float, half, scaled, 0.);
};
See also
tts::sample