Skip to content

Commit

Permalink
Moved parsing regression tests to be unit tests with no external file…
Browse files Browse the repository at this point in the history
… dependency
  • Loading branch information
ddement committed Oct 21, 2024
1 parent 22157a2 commit 8c3d1e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ target_sources(
test_rotor.cpp
test_utilities.cpp
test_controller.cpp
test_yaml_parser.cpp
)
6 changes: 6 additions & 0 deletions tests/unit_tests/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Specify the source files for the unit test executable
target_sources(
openturbine_unit_tests
PRIVATE
test_turbine_parsing.cpp
)
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
#include <gtest/gtest.h>
#include <yaml-cpp/yaml.h>

#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");
Expand All @@ -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

0 comments on commit 8c3d1e5

Please sign in to comment.