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

Generates random values between two bounds. More...

Detailed Description

template<typename Mx, typename Mn>
struct tts::randoms< Mx, Mn >

Generates random values between two bounds.

The constructor takes the lower bound, then the upper bound. Each value is drawn by tts::random_value, uniformly with both bounds included for an integral type, and log-uniformly for a floating-point type. In a build without NDEBUG, a negative bound for an unsigned type stops the run on an assertion.

Template Parameters
MxType of the upper bound
MnType of the lower bound

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <array>
TTS_CASE_WITH("Test tts::randoms generator",
(std::array<float, 10>, std::array<int, 7>, double),
tts::randoms {-4, 4})
<typename T>(T const& args)
{
if constexpr(std::is_arithmetic_v<T>)
{
TTS_GREATER_EQUAL(args, static_cast<T>(-4));
TTS_LESS_EQUAL(args, static_cast<T>(4));
}
else
{
using value_type = typename T::value_type;
for(std::size_t i = 0; i < args.size(); ++i)
{
TTS_GREATER_EQUAL(args[ i ], static_cast<value_type>(-4));
TTS_LESS_EQUAL(args[ i ], static_cast<value_type>(4));
}
}
};

Public Types

using random_type = void
 Marks tts::randoms and the classes derived from it for tts::is_randoms.

Public Member Functions

template<typename D>
void check (tts::type< D >) const
 Stops on a negative bound when D is an unsigned type.