tts v2.3.0
The Tiny Test System
 
Loading...
Searching...
No Matches
The Tiny Test System

The TTS (Tiny Test System) library is a C++ open-source Unit Test library designed following the ideas of libraries like CATCH or LEST.

In addition to classical TDD features, its main goal is to provide:

  • Test over data sets
  • Support for template test cases generation
  • IEEE precision-related tests: ULP, absolute and relative error
  • Customization points for 3rd party types
  • Streamlined behavior for interaction with post-processing scripts

Those features make TTS suitable for numerical-heavy testing.

Supported Compilers

  • g++ 10.3 and superior
  • clang 12 and superior
  • Visual Studio 17 2022 v19.30.30709.0
  • emscripten 3.1.14

A Short Example

#define TTS_MAIN
#include <tts/tts.hpp>
TTS_CASE( "Check expectations" )
{
TTS_EXPECT(true == true);
TTS_EXPECT_NOT(1+1 == 3);
};
TTS_CASE( "Check relationship between values" )
{
double x = 12.34;
TTS_EQUAL( 12.34, x );
TTS_NOT_EQUAL( 17.65, x );
TTS_LESS(1.95f, x);
TTS_GREATER(2*x, x);
TTS_LESS_EQUAL(x,12.35);
};
void foo(bool x) { if(x) throw std::runtime_error{"THIS IS AN ERROR"}; }
TTS_CASE( "Check runtime exceptions" )
{
TTS_THROW(foo(true), std::runtime_error);
TTS_NO_THROW(foo(false));
};
TTS_CASE( "Check precision tests" )
{
double x = 1.;
TTS_ABSOLUTE_EQUAL(x ,1.001, 1e-3 );
TTS_RELATIVE_EQUAL(1,1.1,10);
TTS_ULP_EQUAL(1. + 1e-16, x, 0.5 );
TTS_IEEE_EQUAL(1., x );
};
TTS_CASE( "Check types and expressions" )
{
double d , e;
TTS_EXPR_IS( d + 5 , double);
TTS_EXPR_IS( std::swap(d,e) , void );
TTS_TYPE_IS( std::add_pointer<float const>::type, float const* );
TTS_EXPECT_COMPILES( d, e, { d += e; } );
TTS_EXPECT_NOT_COMPILES(e, { e.foo(); } );
};
#define TTS_EXPECT_NOT(EXPR,...)
Check if a given expression evaluates to false.
Definition: basic.hpp:95
#define TTS_EXPECT(EXPR,...)
Check if a given expression evaluates to true.
Definition: basic.hpp:46
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition: case.hpp:147
#define TTS_THROW(EXPR, EXCEPTION,...)
Checks if a given expression throws an exception of a given type.
Definition: exceptions.hpp:62
#define TTS_NO_THROW(EXPR,...)
Checks if a given expression throws no exception.
Definition: exceptions.hpp:109
#define TTS_LESS_EQUAL(LHS, RHS,...)
Performs less-or-equal-than comparison between two expressions.
Definition: relation.hpp:224
#define TTS_LESS(LHS, RHS,...)
Performs less-than comparison between two expressions.
Definition: relation.hpp:156
#define TTS_NOT_EQUAL(LHS, RHS,...)
Performs inequality comparison between two expressions.
Definition: relation.hpp:123
#define TTS_GREATER_EQUAL(LHS, RHS,...)
Performs greater-or-equal-than comparison between two expressions.
Definition: relation.hpp:260
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition: relation.hpp:90
#define TTS_GREATER(LHS, RHS,...)
Performs greater-than comparison between two expressions.
Definition: relation.hpp:189
#define TTS_ULP_EQUAL(L, R, N,...)
Checks if two values are within a given ULP distance.
Definition: precision.hpp:144
#define TTS_RELATIVE_EQUAL(L, R, N,...)
Checks if values are within a given relative distance expressed as a percentage.
Definition: precision.hpp:102
#define TTS_IEEE_EQUAL(L, R,...)
Checks if two values are exactly within a 0 ULP.
Definition: precision.hpp:198
#define TTS_ABSOLUTE_EQUAL(L, R, N,...)
Checks if the absolute distance between values is less or equal to a threshold.
Definition: precision.hpp:72
#define TTS_EXPECT_NOT_COMPILES(Symbols..., Expression,...)
Checks if an Expression based on a list of Symbols will not compile properly in a SFINAE context.
Definition: types.hpp:202
#define TTS_EXPECT_COMPILES(Symbols..., Expression,...)
Checks if an Expression based on a list of Symbols will compile properly in a SFINAE context.
Definition: types.hpp:154
#define TTS_TYPE_IS(TYPE, REF,...)
Checks if two types satisfy std::is_same_v<Type,Target> == true.
Definition: types.hpp:39
#define TTS_EXPR_IS(EXPR, TYPE,...)
Checks if an Expression evaluates to a value of a given Type.
Definition: types.hpp:87