From b810654af36525b40826704e2870ad8187811302 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Thu, 12 Dec 2019 18:32:54 +0100 Subject: [PATCH] Add tests for DataVariant (AggregateDataVariant actually) --- tests/CMakeLists.txt | 1 + tests/test_DataVariant.cpp | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/test_DataVariant.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 11242857c..60393d75f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,6 +43,7 @@ add_executable (unit_tests test_ContinueProcessor.cpp test_ConcatExpressionProcessor.cpp test_CRSMatrix.cpp + test_DataVariant.cpp test_DoWhileProcessor.cpp test_ExecutionPolicy.cpp test_FakeProcessor.cpp diff --git a/tests/test_DataVariant.cpp b/tests/test_DataVariant.cpp new file mode 100644 index 000000000..eab4f3b12 --- /dev/null +++ b/tests/test_DataVariant.cpp @@ -0,0 +1,48 @@ +#include <catch2/catch.hpp> + +#include <DataVariant.hpp> + +#include <sstream> + +TEST_CASE("DataVariant", "[language]") +{ + SECTION("AggregateDataVariant") + { + AggregateDataVariant aggregate{std::vector<DataVariant>{double{1.3}, int64_t{-3}}}; + + SECTION("size") + { + REQUIRE(aggregate.size() == 2); + } + + SECTION("output") + { + std::stringstream aggregate_output; + aggregate_output << aggregate; + + std::stringstream expected_output; + expected_output << '(' << double{1.3} << ", " << int64_t{-3} << ')'; + REQUIRE(aggregate_output.str() == expected_output.str()); + } + + SECTION("values") + { + REQUIRE(std::get<double>(aggregate[0]) == double{1.3}); + REQUIRE(std::get<int64_t>(aggregate[1]) == int64_t{-3}); + } + + SECTION("Copy") + { + AggregateDataVariant aggregate_copy{aggregate}; + + REQUIRE(aggregate.size() == aggregate_copy.size()); + + for (size_t i = 0; i < aggregate.size(); ++i) { + REQUIRE(aggregate[i].index() == aggregate_copy[i].index()); + } + + REQUIRE(std::get<double>(aggregate[0]) == std::get<double>(aggregate_copy[0])); + REQUIRE(std::get<int64_t>(aggregate[1]) == std::get<int64_t>(aggregate_copy[1])); + } + } +} -- GitLab