TTS v4.1.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++ 11.1 and superior
  • clang 13 and superior
  • Visual Studio 17 2022 v19.30.30709.0
  • clang-CL 15.0.1 or superior
  • emscripten 3.1.14

A Short Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
#include <stdexcept>
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,0.1);
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,...)
Checks that an expression is false.
Definition basic.hpp:97
#define TTS_EXPECT(EXPR,...)
Checks that an expression is true.
Definition basic.hpp:69
#define TTS_THROW(EXPR, EXCEPTION,...)
Checks that an expression throws an exception of type EXCEPTION.
Definition exceptions.hpp:85
#define TTS_NO_THROW(EXPR,...)
Checks that an expression throws no exception.
Definition exceptions.hpp:123
#define TTS_ULP_EQUAL(L, R, N,...)
Checks that two values are at most N ULP apart.
Definition precision.hpp:215
#define TTS_RELATIVE_EQUAL(L, R, N,...)
Checks that two values are within a combined relative and absolute tolerance N.
Definition precision.hpp:179
#define TTS_IEEE_EQUAL(L, R,...)
Checks that two values are 0 ULP apart, that is equal or both NaN.
Definition precision.hpp:244
#define TTS_ABSOLUTE_EQUAL(L, R, N,...)
Checks that two values are at most N apart.
Definition precision.hpp:148
#define TTS_LESS_EQUAL(LHS, RHS,...)
Checks that LHS is less than or equal to RHS.
Definition relation.hpp:270
#define TTS_LESS(LHS, RHS,...)
Checks that LHS is less than RHS.
Definition relation.hpp:228
#define TTS_NOT_EQUAL(LHS, RHS,...)
Checks that two expressions are not equal.
Definition relation.hpp:207
#define TTS_GREATER_EQUAL(LHS, RHS,...)
Checks that LHS is greater than or equal to RHS.
Definition relation.hpp:291
#define TTS_EQUAL(LHS, RHS,...)
Checks that two expressions are equal.
Definition relation.hpp:186
#define TTS_GREATER(LHS, RHS,...)
Checks that LHS is greater than RHS.
Definition relation.hpp:249
#define TTS_CASE(ID)
Defines a test case and registers it with the test driver.
Definition case.hpp:304
#define TTS_EXPECT_NOT_COMPILES(Symbols..., Expression,...)
Checks that an expression on the given symbols does not compile.
Definition types.hpp:205
#define TTS_EXPECT_COMPILES(Symbols, Expression,...)
Checks that an expression on the given symbols compiles.
Definition types.hpp:171
#define TTS_TYPE_IS(TYPE, REF,...)
Checks that two types are the same.
Definition types.hpp:95
#define TTS_EXPR_IS(EXPR, TYPE,...)
Checks that an expression has the type TYPE.
Definition types.hpp:127