cpp : Added documentation
This commit is contained in:
@ -2,14 +2,25 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
* @brief Test if a given result is equal of the expected one and log result
|
||||
*
|
||||
* @tparam T type of returning values
|
||||
* @param name of the unit test
|
||||
* @param expected result of the function call
|
||||
* @param result of the function
|
||||
*/
|
||||
template<typename T>
|
||||
void Assert(const char* const name, const T& expected, const T& result) noexcept {
|
||||
static void Assert(const char* const name, const T& expected, const T& result) noexcept {
|
||||
if(expected != result){
|
||||
std::cerr << "For test named " << name << " Expected '" << expected << "' but got '" << result << "' instead\n";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test suite for the format_byte_size output
|
||||
*/
|
||||
void format_byte_size_test(void) noexcept {
|
||||
Assert("format_byte_size null", std::string("0B"), format_byte_size(static_cast<uint64_t>(0)));
|
||||
Assert("format_byte_size byte", std::string("1B"), format_byte_size(static_cast<uint64_t>(1)));
|
||||
@ -26,6 +37,9 @@ void format_byte_size_test(void) noexcept {
|
||||
Assert("format_byte_size max", std::string("15EB 1023PB 1023TB 1023GB 1023MB 1023KB 1023B"), format_byte_size(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test suite for the format_time output
|
||||
*/
|
||||
void format_time_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Unit_of_time
|
||||
Assert("format_time null", std::string("0s"), format_time(static_cast<uint64_t>(0)));
|
||||
@ -80,6 +94,9 @@ void format_time_test(void) noexcept {
|
||||
Assert("format_time max", std::string("5849424173c 55y 3w 5j 7h 15s"), format_time(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test suite for the format_time_ns output
|
||||
*/
|
||||
void format_time_ns_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Unit_of_time
|
||||
Assert("format_time_ns null", std::string("0ns"), format_time_ns(static_cast<uint64_t>(0)));
|
||||
@ -140,6 +157,9 @@ void format_time_ns_test(void) noexcept {
|
||||
Assert("format_time_ns max", std::string("5c 84y 11M 2j 23h 34m 33s 709ms 551us 615ns"), format_time_ns(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test suite for the thousand_sep output
|
||||
*/
|
||||
void thousand_sep_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Names_of_large_numbers
|
||||
Assert("thousand_sep null", std::string("0"), thousand_sep(static_cast<uint64_t>(0)));
|
||||
|
Reference in New Issue
Block a user