From f78a98797f233d1457afbd9362db339780ccac54 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 12 Aug 2019 11:53:23 +0200 Subject: [PATCH] more testing --- slsDetectorSoftware/tests/test-Result.cpp | 9 ++++++ slsSupportLib/include/TypeTraits.h | 15 ++++++++- slsSupportLib/tests/test-TypeTraits.cpp | 37 +++++++++++++++++++++-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/tests/test-Result.cpp b/slsDetectorSoftware/tests/test-Result.cpp index 8b1872791..352df0f68 100644 --- a/slsDetectorSoftware/tests/test-Result.cpp +++ b/slsDetectorSoftware/tests/test-Result.cpp @@ -34,6 +34,15 @@ TEST_CASE("Like vector it can be constructed from size and value") { REQUIRE(res[4] == 7); } +TEST_CASE("Result can be iterated using modern syntax"){ + Result res{0,1,2,3,4,5}; + + int i = 0; + for (const auto& r:res) + REQUIRE(r == i++); + +} + TEST_CASE("Calling squash on an empty Result produces default value") { Result res; REQUIRE(res.squash() == 0.); diff --git a/slsSupportLib/include/TypeTraits.h b/slsSupportLib/include/TypeTraits.h index 2a5409e78..b7297389c 100644 --- a/slsSupportLib/include/TypeTraits.h +++ b/slsSupportLib/include/TypeTraits.h @@ -4,7 +4,7 @@ namespace sls { /** - * Type trait to check if atemplate parameter is a std::chrono::duration + * Type trait to check if a template parameter is a std::chrono::duration */ template @@ -22,6 +22,19 @@ struct is_duration().zero())>, void>::type> : public std::true_type {}; +/** + * Has str method + */ +template struct has_str : std::false_type {}; + +template struct has_str_helper {}; + +template +struct has_str().str())>, + void>::type> : public std::true_type {}; + /** * Type trait to evaluate if template parameter is * complying with a standard container diff --git a/slsSupportLib/tests/test-TypeTraits.cpp b/slsSupportLib/tests/test-TypeTraits.cpp index 20f1c7e9f..042eee3ac 100644 --- a/slsSupportLib/tests/test-TypeTraits.cpp +++ b/slsSupportLib/tests/test-TypeTraits.cpp @@ -1,10 +1,41 @@ -#include "catch.hpp" #include "TypeTraits.h" -#include +#include "catch.hpp" #include +#include +#include +#include -TEST_CASE("something", "[n3]"){ +//Dummy classes only used here for testing +class DummyWithStr { + public: + std::string str(); +}; + +class DummyNoStr { + public: + std::string somethingelse(); +}; + +TEST_CASE("sls::is_container") { CHECK(sls::is_container>::value == true); CHECK(sls::is_container>::value == true); +} + +TEST_CASE("Check for str() method") { + REQUIRE(sls::has_str::value == true); + REQUIRE(sls::has_str::value == false); +} + +TEST_CASE("Check for str() on ostream") { + REQUIRE(sls::has_str::value == true); +} + +TEST_CASE("sls::is_duration"){ + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); + REQUIRE(sls::is_duration::value == true); + + REQUIRE(sls::is_duration::value == false); + REQUIRE(sls::is_duration>::value == false); } \ No newline at end of file