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

Macros for performing sequence-wide checks. More...

Macros

#define TTS_ALL_ABSOLUTE_EQUAL(L, R, N, ...)
 Checks that two sequences have the same size and that their elements are at most N apart.
#define TTS_ALL_EQUAL(L, R, ...)
 Checks that two sequences have the same size and equal elements.
#define TTS_ALL_IEEE_EQUAL(L, R, ...)
 Checks that two sequences have the same size and that their elements are 0 ULP apart, that is equal or both NaN.
#define TTS_ALL_RELATIVE_EQUAL(L, R, N, ...)
 Checks that two sequences have the same size and that their elements are within a combined relative and absolute tolerance N.
#define TTS_ALL_ULP_EQUAL(L, R, N, ...)
 Checks that two sequences have the same size and that their elements are at most N ULP apart.

Macro Definition Documentation

◆ TTS_ALL_ABSOLUTE_EQUAL

#define TTS_ALL_ABSOLUTE_EQUAL ( L,
R,
N,
... )

#include <tts/test/sequence.hpp>

Checks that two sequences have the same size and that their elements are at most N apart.

Measures each pair of elements with tts::absolute_check, as TTS_ABSOLUTE_EQUAL does.

Parameters
L,RSequences to compare, each with a size() member or a size found by argument-dependent lookup.
NLargest distance accepted.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <vector>
#include <list>
TTS_CASE("Absolute distance over sequences")
{
std::vector v {1.f, 2.f, 3.f, -1.f};
std::list w {1.f, 7.f, 3.f, -5.f};
};

◆ TTS_ALL_EQUAL

#define TTS_ALL_EQUAL ( L,
R,
... )

#include <tts/test/sequence.hpp>

Checks that two sequences have the same size and equal elements.

Compares the elements as TTS_ALL_ABSOLUTE_EQUAL does with N = 0.

Parameters
L,RSequences to compare, each with a size() member or a size found by argument-dependent lookup.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <vector>
#include <list>
TTS_CASE("Equality over sequences")
{
std::vector v {1.f, 2.f, 3.f, -5.f};
std::list w {1.f, 2.f, 3.f, -5.f};
};

◆ TTS_ALL_IEEE_EQUAL

#define TTS_ALL_IEEE_EQUAL ( L,
R,
... )

#include <tts/test/sequence.hpp>

Checks that two sequences have the same size and that their elements are 0 ULP apart, that is equal or both NaN.

Compares the elements as TTS_ALL_ULP_EQUAL does with N = 0.

Parameters
L,RSequences to compare, each with a size() member or a size found by argument-dependent lookup.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <vector>
#include <list>
TTS_CASE("IEEE distance over sequences")
{
float x = std::numeric_limits<float>::quiet_NaN();
std::vector v {1.f, 2.f, 3.f, x};
std::list w {1.f, 2.f, 3.f, x};
};

◆ TTS_ALL_RELATIVE_EQUAL

#define TTS_ALL_RELATIVE_EQUAL ( L,
R,
N,
... )

#include <tts/test/sequence.hpp>

Checks that two sequences have the same size and that their elements are within a combined relative and absolute tolerance N.

Each pair of elements a and b passes if abs(a - b) <= N * max(1, abs(a), abs(b)), the combined tolerance test of tts::relative_check. N acts as an absolute tolerance where both values are at most 1 in magnitude, and as a relative one elsewhere. Two NaNs or two equal infinities pass, and any other NaN or infinity fails.

N is a ratio, so 0.005 accepts half a percent. On an arithmetic type, a finite N of 1 or more fails the check with a message asking for N divided by a hundred, since TTS 3 took a percentage.

Parameters
L,RSequences to compare, each with a size() member or a size found by argument-dependent lookup.
NTolerance, as a ratio.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <vector>
#include <list>
TTS_CASE("Relative distance over sequences")
{
std::vector v {1.f, 2.f, 3.f, -5.f};
std::list w {1.f, 2.f, 3.1f, -5.f};
TTS_ALL_RELATIVE_EQUAL(v, w, 0.0333);
};

◆ TTS_ALL_ULP_EQUAL

#define TTS_ALL_ULP_EQUAL ( L,
R,
N,
... )

#include <tts/test/sequence.hpp>

Checks that two sequences have the same size and that their elements are at most N ULP apart.

Measures each pair of elements with tts::ulp_check, as TTS_ULP_EQUAL does.

Parameters
L,RSequences to compare, each with a size() member or a size found by argument-dependent lookup.
NLargest distance accepted, in ULP.
...REQUIRED ends the run when the check fails.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <vector>
#include <list>
TTS_CASE("ULP distance over sequences")
{
std::vector v {1.f, 2.f, 3.f, -5.f};
std::list w {1.f + 1e-7f, 2.f, 3.f, -5.f};
TTS_ALL_ULP_EQUAL(v, w, 0.5);
};