From 8c3d1e5c001b5236360d0e1330511f5d16031b83 Mon Sep 17 00:00:00 2001 From: dcdemen Date: Mon, 21 Oct 2024 12:33:07 -0600 Subject: [PATCH] Moved parsing regression tests to be unit tests with no external file dependency --- tests/unit_tests/CMakeLists.txt | 1 + tests/unit_tests/regression/CMakeLists.txt | 1 - tests/unit_tests/utilities/CMakeLists.txt | 6 +++++ .../test_turbine_parsing.cpp} | 25 ++++++++----------- 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 tests/unit_tests/utilities/CMakeLists.txt rename tests/unit_tests/{regression/test_yaml_parser.cpp => utilities/test_turbine_parsing.cpp} (52%) diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 986e66dc..832d4c81 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(regression) add_subdirectory(solver) add_subdirectory(state) add_subdirectory(system) +add_subdirectory(utilities) # Specify the source files for the unit tests target_sources(openturbine_unit_tests PRIVATE utest_main.cpp) diff --git a/tests/unit_tests/regression/CMakeLists.txt b/tests/unit_tests/regression/CMakeLists.txt index fdbaac59..5dcbec46 100644 --- a/tests/unit_tests/regression/CMakeLists.txt +++ b/tests/unit_tests/regression/CMakeLists.txt @@ -10,5 +10,4 @@ target_sources( test_rotor.cpp test_utilities.cpp test_controller.cpp - test_yaml_parser.cpp ) diff --git a/tests/unit_tests/utilities/CMakeLists.txt b/tests/unit_tests/utilities/CMakeLists.txt new file mode 100644 index 00000000..e29c28e4 --- /dev/null +++ b/tests/unit_tests/utilities/CMakeLists.txt @@ -0,0 +1,6 @@ +# Specify the source files for the unit test executable +target_sources( + openturbine_unit_tests + PRIVATE + test_turbine_parsing.cpp +) diff --git a/tests/unit_tests/regression/test_yaml_parser.cpp b/tests/unit_tests/utilities/test_turbine_parsing.cpp similarity index 52% rename from tests/unit_tests/regression/test_yaml_parser.cpp rename to tests/unit_tests/utilities/test_turbine_parsing.cpp index 2ff0055e..5ed051c7 100644 --- a/tests/unit_tests/regression/test_yaml_parser.cpp +++ b/tests/unit_tests/utilities/test_turbine_parsing.cpp @@ -1,25 +1,21 @@ #include #include -#include "test_utilities.hpp" - #include "src/utilities/scripts/windio_mapped_structs.hpp" namespace openturbine::tests { -TEST(ParserTest, ParseIEA15MWBasicInfo) { - const std::filesystem::path projectRoot = FindProjectRoot(); - const std::filesystem::path yamlPath = projectRoot / "src/utilities/scripts/IEA-15-240-RWT.yaml"; - const YAML::Node config = YAML::LoadFile(yamlPath.string()); +TEST(ParserTest, ParseIEA15MWName) { + const std::string input = "name: IEA 15MW Offshore Reference Turbine, with taped chord tip design"; + const YAML::Node config = YAML::Load(input); Turbine turbine; turbine.parse(config); ASSERT_EQ(turbine.name, "IEA 15MW Offshore Reference Turbine, with taped chord tip design"); } TEST(ParserTest, ParseIEA15MWAssembly) { - const std::filesystem::path projectRoot = FindProjectRoot(); - const std::filesystem::path yamlPath = projectRoot / "src/utilities/scripts/IEA-15-240-RWT.yaml"; - const YAML::Node config = YAML::LoadFile(yamlPath.string()); + const std::string input = "assembly:\n turbine_class: I\n turbulence_class: B\n drivetrain: direct_drive\n rotor_orientation: Upwind\n number_of_blades: 3\n hub_height: 150\n rotor_diameter: 241.94\n rated_power: 15.e+6\n lifetime: 25\n"; + const YAML::Node config = YAML::Load(input); Turbine turbine; turbine.parse(config); ASSERT_EQ(turbine.assembly.turbine_class, "I"); @@ -33,13 +29,14 @@ TEST(ParserTest, ParseIEA15MWAssembly) { ASSERT_EQ(turbine.assembly.lifetime, 25.); } -TEST(ParserTest, ParseIEA15MWMaterials) { - const std::filesystem::path projectRoot = FindProjectRoot(); - const std::filesystem::path yamlPath = projectRoot / "src/utilities/scripts/IEA-15-240-RWT.yaml"; - const YAML::Node config = YAML::LoadFile(yamlPath.string()); +TEST(ParserTest, ParseIEA15MWMultipleMaterials) { + const std::string input = "materials:\n [name: first, name: second]"; + const YAML::Node config = YAML::Load(input); Turbine turbine; turbine.parse(config); - ASSERT_EQ(turbine.materials.size(), 11); + EXPECT_EQ(turbine.materials.size(), 2); + EXPECT_EQ(turbine.materials[0].name, "first"); + EXPECT_EQ(turbine.materials[1].name, "second"); } } // namespace openturbine::tests