Tiny Test System is a C++20 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
TTS is thus suitable for numerical-heavy testing.
- g++ 10.3 and superior
- clang 12 and superior
- Visual Studio 17 2022 v19.30.30709.0
- clang-CL 15.0.1 or superior
- emscripten 3.1.14
See it live on Compiler Explorer
#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.5;
TTS_EQUAL( 12.5f, x );
TTS_NOT_EQUAL( 17.65, x );
TTS_LESS(1.95f, x);
TTS_GREATER(2*x, x);
TTS_LESS_EQUAL(x,13);
TTS_GREATER_EQUAL(x,3.5f);
};
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 );
};
This library is licensed under the Boost Software License 1.0 License:
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.