TTS v4.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 read backward: the last value is start and every earlier one stands one step above it. I.e., for a size N, the produced values are: start+(N-1)*step, ..., start+2*step, start+step, start.

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),
<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;
auto const last = ramp1.size() - 1;
for(std::size_t i = 0; i < ramp1.size(); ++i)
{
TTS_EQUAL(ramp1[ i ], static_cast<value_type>(65) + static_cast<value_type>(last - i));
}
for(std::size_t i = 0; i < ramp2.size(); ++i)
{
TTS_EQUAL(ramp2[ i ], static_cast<value_type>(10) + static_cast<value_type>((last - i) * 2));
}
}
};