-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added missing test class ConvertTest and started implementation of tests
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "ConvertTest.hpp" | ||
|
||
#include "matador/utils/convert.hpp" | ||
#include "matador/utils/date.hpp" | ||
#include "matador/utils/time.hpp" | ||
#include "matador/utils/types.hpp" | ||
|
||
ConvertTest::ConvertTest() | ||
: unit_test("convert", "convert test") | ||
{ | ||
add_test("convert", [this] { test_convert_integral(); }, "convert test"); | ||
} | ||
|
||
using namespace matador::utils; | ||
|
||
template<typename From, typename To> | ||
void ConvertTest::validate_conversion(From from) | ||
{ | ||
To to{}; | ||
convert(to, from); | ||
|
||
UNIT_ASSERT_EQUAL(static_cast<To>(from), to); | ||
} | ||
|
||
template<typename From, typename To> | ||
void ConvertTest::validate_conversion(From from, To expected_to) | ||
{ | ||
To to{}; | ||
convert(to, from); | ||
|
||
UNIT_ASSERT_EQUAL(to, expected_to); | ||
} | ||
|
||
template<typename From> | ||
void ConvertTest::validate_integral_conversion(From from) | ||
{ | ||
validate_conversion<From, char>(from); | ||
validate_conversion<From, short>(from); | ||
validate_conversion<From, int>(from); | ||
validate_conversion<From, long>(from); | ||
validate_conversion<From, long long>(from); | ||
} | ||
|
||
void ConvertTest::test_convert_integral() | ||
{ | ||
validate_integral_conversion<char>(-56); | ||
validate_integral_conversion<short>(-127); | ||
validate_integral_conversion<int>(-1234567); | ||
validate_integral_conversion<long>(-9876543); | ||
validate_integral_conversion<long long>(-123456790); | ||
|
||
validate_integral_conversion<unsigned char>(56); | ||
validate_integral_conversion<unsigned short>(127); | ||
validate_integral_conversion<unsigned int>(1234567); | ||
validate_integral_conversion<unsigned long>(9876543); | ||
validate_integral_conversion<unsigned long long>(123456790); | ||
|
||
validate_conversion<short, char>(513, 1); | ||
validate_conversion<int, char>(514, 2); | ||
validate_conversion<long, char>(515, 3); | ||
validate_conversion<long long, char>(516, 4); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef MATADOR_CONVERTTEST_HPP | ||
#define MATADOR_CONVERTTEST_HPP | ||
|
||
#include "matador/unit/unit_test.hpp" | ||
|
||
class ConvertTest : public matador::unit_test | ||
{ | ||
public: | ||
ConvertTest(); | ||
|
||
void test_convert_integral(); | ||
|
||
private: | ||
template<typename From, typename To> | ||
void validate_conversion(From from); | ||
template<typename From, typename To> | ||
void validate_conversion(From from, To expected_to); | ||
template<typename From> | ||
void validate_integral_conversion(From from); | ||
}; | ||
|
||
|
||
#endif //MATADOR_CONVERTTEST_HPP |