TTS v3.0.0
The Tiny Test System
 
Loading...
Searching...
No Matches
tts::reverse_ramp< T, U > Struct Template Reference

Defines a data generator that produce a reverse ramp of data. More...

Detailed Description

template<typename T, typename U = T>
struct tts::reverse_ramp< T, U >

Defines a data generator that produce a reverse ramp of data.

This generator produces a ramp starting from a final value and decreasing by a fixed step at each call. I.e., for a size N, the produced values are: start, start-step, start-2*step, ..., start-(N-1)*step.

Template Parameters
TType of the initial value
UType of the step value

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <array>
TTS_CASE_WITH("Test tts::reverse_ramp generator",
(std::array<float, 10>, int, double),
tts::reverse_ramp {10, 2})<typename T>(T const& ramp1, T const& ramp2)
{
if constexpr(std::is_arithmetic_v<T>)
{
TTS_EQUAL(ramp1, static_cast<T>(65));
TTS_EQUAL(ramp2, static_cast<T>(10));
}
else
{
using value_type = typename T::value_type;
for(std::size_t i = 0; i < ramp1.size(); ++i)
{
TTS_EQUAL(ramp1[ i ], static_cast<value_type>(65) - static_cast<value_type>(i));
}
for(std::size_t i = 0; i < ramp2.size(); ++i)
{
TTS_EQUAL(ramp2[ i ], static_cast<value_type>(10) - static_cast<value_type>(i * 2));
}
}
};
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition relation.hpp:134
#define TTS_CASE_WITH(ID, TYPES,...)
Introduces a template test case providing dynamically generated data to the test code.
Definition case.hpp:201
auto constexpr typename_
Evaluates to an object containing the name of the type T in readable form.
Definition typename.hpp:126
Defines a data generator that produce a reverse ramp of data.
Definition generator.hpp:203