Files
FESADev/tests/reference/eigen_reference_cases_test.cpp
T

80 lines
2.9 KiB
C++

#include <gtest/gtest.h>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <stdexcept>
#include <string>
#include "eigen_reference_comparison.h"
#include "fesa/app/fesa_application.h"
#ifndef FESA_TEST_SOURCE_DIR
#error FESA_TEST_SOURCE_DIR must identify the repository root.
#endif
#ifndef FESA_TEST_BINARY_DIR
#error FESA_TEST_BINARY_DIR must identify the CMake binary root.
#endif
namespace {
std::string ReadBytes(const std::filesystem::path& path) {
std::ifstream stream{path, std::ios::binary};
if (!stream) {
throw std::runtime_error{"Unable to read declared eigen artifact."};
}
return {std::istreambuf_iterator<char>{stream},
std::istreambuf_iterator<char>{}};
}
// E2-C25.
TEST(EigenReference, RunsOriginalInputAndComparesAllModalFrameIdentities) {
const std::filesystem::path source_root{FESA_TEST_SOURCE_DIR};
const std::filesystem::path reference_directory =
std::filesystem::path{FESA_TEST_BINARY_DIR} / "reference" /
"eigen-execution";
std::filesystem::create_directories(reference_directory);
for (const auto& name : {"shellNL-eigen-meshfine.inp",
"shellNL-eigen-meshfine eigenvalues.txt"}) {
std::filesystem::copy_file(
source_root / "reference" / "shellNL-eigen-meshfine" / name,
reference_directory / name,
std::filesystem::copy_options::overwrite_existing);
}
const std::filesystem::path input =
reference_directory / "shellNL-eigen-meshfine.inp";
const std::filesystem::path text =
reference_directory / "shellNL-eigen-meshfine eigenvalues.txt";
const std::string input_before = ReadBytes(input);
const std::string text_before = ReadBytes(text);
fesa::FesaApplication application;
const int exit_code = application.Run({input.string()});
EXPECT_EQ(ReadBytes(input), input_before);
EXPECT_EQ(ReadBytes(text), text_before);
ASSERT_EQ(exit_code, 0);
const std::filesystem::path results =
reference_directory / "shellNL-eigen-meshfine_results.h5";
ASSERT_TRUE(std::filesystem::is_regular_file(results));
const auto comparison = fesa::test::EigenReferenceComparison::Compare(
{"shellnl-eigen-meshfine", input, text, results});
ASSERT_TRUE(comparison.HasValue());
EXPECT_TRUE(comparison.Value().passed);
EXPECT_EQ(comparison.Value().source_step_name, "Step-2");
EXPECT_EQ(comparison.Value().requested_mode_count, 10U);
ASSERT_EQ(comparison.Value().rows.size(), 10U);
ASSERT_EQ(comparison.Value().families.size(), 10U);
for (std::size_t index = 0U; index < comparison.Value().rows.size();
++index) {
EXPECT_EQ(comparison.Value().rows[index].mode_id, index + 1U);
EXPECT_EQ(comparison.Value().rows[index].component, "Value");
EXPECT_EQ(comparison.Value().families[index].row_count, 1U);
EXPECT_TRUE(comparison.Value().families[index].passed);
}
EXPECT_EQ(ReadBytes(input), input_before);
EXPECT_EQ(ReadBytes(text), text_before);
}
} // namespace