Commit 1ab4ef1e authored by David Frank's avatar David Frank
Browse files

#20 Add test for DataContainerFormatter

parent 3487f940
#pragma once
#include <elsaDefines.h>
#include "elsaDefines.h"
#include "DataContainer.h"
#include <iomanip>
#include <iostream>
#include <iterator>
......@@ -73,7 +75,7 @@ namespace elsa
}
/// stream a pretty format to is using the current configuration.
void format(std::ostream& os, const elsa::DataContainer<data_t>& dc)
void format(std::ostream& os, const DataContainer<data_t>& dc)
{
using namespace std::string_literals;
......@@ -224,7 +226,7 @@ namespace elsa
*/
template <typename T>
std::function<std::ostream&(std::ostream& os, const T& elem)>
get_element_formatter(const elsa::DataContainer<T>& dc)
get_element_formatter(const DataContainer<T>& dc)
{
if constexpr (elsa::isComplex<T>) {
// format both components independently
......
......@@ -26,3 +26,4 @@ ELSA_DOCTEST(ExpressionTemplates)
ELSA_DOCTEST(DataHandlers)
ELSA_DOCTEST(DataHandlerMap)
ELSA_DOCTEST(DataContainer)
ELSA_DOCTEST(DataContainerFormatter)
#include "doctest/doctest.h"
#include "DataContainerFormatter.hpp"
#include "VolumeDescriptor.h"
using namespace elsa;
using namespace doctest;
TEST_SUITE_BEGIN("core");
TEST_CASE("DataContainerFormatter: default config")
{
using data_t = float;
std::stringstream buffer;
DataContainerFormatter<data_t> formatter;
GIVEN("A 1D DataContainer with arbitrary values")
{
IndexVector_t numCoeff(1);
numCoeff << 10;
DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
dc = 1;
THEN("Formatting writes correctly to the stream")
{
formatter.format(buffer, dc);
auto resultString = buffer.str();
REQUIRE_EQ(resultString,
"DataContainer<dims=1, shape=(10)>\n[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]");
}
}
GIVEN("A larger 1D DataContainer with arbitrary values")
{
IndexVector_t numCoeff(1);
numCoeff << 15;
DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
dc = 1;
THEN("Formatting writes abbreviated to the stream")
{
formatter.format(buffer, dc);
auto resultString = buffer.str();
REQUIRE_EQ(
resultString,
"DataContainer<dims=1, shape=(15)>\n[1, 1, 1, 1, 1, 1, ..., 1, 1, 1, 1, 1, 1]");
}
}
GIVEN("A 2D DataContainer with arbitrary values")
{
IndexVector_t numCoeff(2);
numCoeff << 5, 3;
DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
dc = 1;
THEN("Formatting writes correctly to the stream")
{
formatter.format(buffer, dc);
auto resultString = buffer.str();
REQUIRE_EQ(resultString,
R"(DataContainer<dims=2, shape=(5 3)>
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])");
}
}
}
TEST_SUITE_END();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment