diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 11242857c4741c0732c8f764fde4cc6d894595a1..60393d75f39f4a39b4f59dd502f2b78b22d69bb6 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 0000000000000000000000000000000000000000..eab4f3b12c6b8ff2f9a96a8400195f57855e2883 --- /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])); + } + } +}